Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 3rd, 2008, 06:32 PM
Authorized User
 
Join Date: Apr 2008
Location: , , .
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



Reply With Quote
  #2 (permalink)  
Old April 3rd, 2008, 07:28 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
  #3 (permalink)  
Old April 3rd, 2008, 07:37 PM
Authorized User
 
Join Date: Apr 2008
Location: , , .
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()

Reply With Quote
  #4 (permalink)  
Old April 3rd, 2008, 07:42 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
  #5 (permalink)  
Old April 3rd, 2008, 07:58 PM
Authorized User
 
Join Date: Apr 2008
Location: , , .
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

Reply With Quote
  #6 (permalink)  
Old April 3rd, 2008, 08:05 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
  #7 (permalink)  
Old April 4th, 2008, 03:11 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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 -/
Reply With Quote
  #8 (permalink)  
Old April 4th, 2008, 09:16 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:07 AM.


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