Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2008, 06:32 PM
Authorized User
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default loaded usercontrol

hello!

i wonder if anybody can help me with this... it's a little problem i have with an aspx page and a usercontrol

i already loaded my usercontrol from MyControl.ascx into myPage.aspx with this:

MyControl control;
control = (MyControl)LoadControl("MyControl.ascx");
placeHolder1.Controls.Add(control);

to here, everything it's ok... so, my user control has a gridview and i want to raise its events on the page I'm loading the user control but i can't, for example; i want to use the SelectedIndexChanged event of the gridview in the user control in the page that is loaded, or i also want to use the gridview properties but i can't...

what can i do if i want to do all this??

i hope you understand my problem and help me...

thanks a lot!

BR



 
Old April 3rd, 2008, 07:28 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What do you mean you can't? Also is there any reason why you MUST use LoadControl? Normally you only use this if the control you need to load is not determined until runtime.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old April 3rd, 2008, 07:37 PM
Authorized User
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in fact, i need to load my user control at runtime... that's the reason i used LoadControl()

 
Old April 3rd, 2008, 07:42 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Thats great, but you didn't answer the more important of the two questions.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old April 3rd, 2008, 07:58 PM
Authorized User
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i didn't mean "i can't" but, "i can't do it YET", because i've been searching on forums and some other pages on the web...

thanks


BR

 
Old April 3rd, 2008, 08:05 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I assume you are trying to access these properties/events from the container page? Is there any reason why you cant deal with these things from inside the user control itself?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old April 4th, 2008, 03:11 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

If you want events from within your user control to be handled by the page then you need to handle the event for the sub control (e.g. gridview inside user control) and then raise an event you define on the user control.

Then you can add that new event in code in your page load. You must also set the control's ID so that the events can be hooked up by the asp.net engine.

/- Sam Judson : Wrox Technical Editor -/
 
Old April 4th, 2008, 09:16 AM
Registered User
 
Join Date: Mar 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi BR,

I also don't know what you mean by "can't do it". You don't know how? You're getting errors? If so what errors? You're not getting the result you expected?...

I went through a similar scenario a few weeks ago where I wanted to load controls at runtime and it just became really complicated and problematic to manage the control load, it's state, etc. on postback of the .aspx page.

After many hours of searching and advice from smarter people than me, I admitted defeat. My/their solution was to drag the controls onto my page and hide/show them as needed. This was a viable solution as I only had a couple of controls and having 2 or 3 on the page VS having only one loaded at runtime isn't very expensive.

Anna






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to check if page is already loaded? phpworker Javascript How-To 0 July 31st, 2005 11:49 AM
Check whether a form is already loaded madhukp VB How-To 1 September 8th, 2004 11:34 PM
Getting the path name of a loaded object. jtrifts VB How-To 2 August 26th, 2004 02:17 PM
How can i know that a form is loaded. sharma_atin VB How-To 1 September 1st, 2003 10:51 AM
Frames loaded kilika VBScript 1 August 11th, 2003 06:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.