Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > How do I capture events fired in child user controls?

Reply
Thread Tools

How do I capture events fired in child user controls?

 
 
Justin
Guest
Posts: n/a
 
      01-27-2004
First, let me give you some background on what I am trying to accomplish. I have a page which contains a custom user control, lets call it Navigator, that has some buttons next, back, etc. Navigator also contains a placeholder in which I load other custom user controls when next or back is clicked. These custom user controls contain textboxes and dropdown lists which contain info that I need in Navigator.

The problem is, when as a user I change text in the textboxes of Navigator's placeholder child controls no events are firing and the text is not being saved. Now, I am new to the whole asp.net world and I am thinking that I am missing some very fundamental knowledge that might help me capture the events of the child controls. Does this problem sound familiar to anyone? If so, what might I be doing wrong? Please help

Thanks

Justin
 
Reply With Quote
 
 
 
 
Eran Amitai
Guest
Posts: n/a
 
      01-27-2004
Justin, I know there are user controls and custom controls. What are custom
user controls?

Eran

"Justin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> First, let me give you some background on what I am trying to accomplish.

I have a page which contains a custom user control, lets call it Navigator,
that has some buttons next, back, etc. Navigator also contains a
placeholder in which I load other custom user controls when next or back is
clicked. These custom user controls contain textboxes and dropdown lists
which contain info that I need in Navigator.
>
> The problem is, when as a user I change text in the textboxes of

Navigator's placeholder child controls no events are firing and the text is
not being saved. Now, I am new to the whole asp.net world and I am thinking
that I am missing some very fundamental knowledge that might help me capture
the events of the child controls. Does this problem sound familiar to
anyone? If so, what might I be doing wrong? Please help.
>
> Thanks,
>
> Justin



 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      01-27-2004
hi justin, can you provide some code as to how your going about adding your
controls to the placeholder, when you are setting the properties of your
dynamically added controls. You need to set properties and the events after
the controls have been added to the controls collections. And make sure this
code is run also after postback.

Futhermore can you elaborate as to what you mean by no events are fire --in
shorts the steps you have taken to hook up event handlers etc
Each user control has a code behind file associated with it and this is the
right place to code. Include any event-handling methods here and also
declare public instances of the ASP.NET server controls that you plan to use
within your usercontrol here. Keep in mind, however, that user controls
encapsulate their own events and send the event information through the
containing page to be processed. Do not include user control event handlers
in the containing page, write them in the codebehind file that generates the
user control.

a straight forward answer to your post heading "How do i capture events
fired in child user controls is to use event bubbling. That is you bubble up
all events in your child user controls up to their containers and take
action there or bubble them up further etc. Not sure if this is what you
want but makes sense to me.
To bubble up events you need to override the onBubbleEvent function for you
usercontrol and then capture these in your parent container for that
usercontrol.


"Justin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> First, let me give you some background on what I am trying to accomplish.

I have a page which contains a custom user control, lets call it Navigator,
that has some buttons next, back, etc. Navigator also contains a
placeholder in which I load other custom user controls when next or back is
clicked. These custom user controls contain textboxes and dropdown lists
which contain info that I need in Navigator.
>
> The problem is, when as a user I change text in the textboxes of

Navigator's placeholder child controls no events are firing and the text is
not being saved. Now, I am new to the whole asp.net world and I am thinking
that I am missing some very fundamental knowledge that might help me capture
the events of the child controls. Does this problem sound familiar to
anyone? If so, what might I be doing wrong? Please help.
>
> Thanks,
>
> Justin



 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      01-27-2004
try overriding the onbubbleEvent function of your container and check to see
who is postingback, if its the onNext button try and retrieve your text.
http://www.aboutfortunate.com/Default.aspx

As you will note from that code in the link, they are overriding the
onBubbleEvent of the container, in your case this is the same place where
you are trying to retrieve the values. That is where you loaded the
control(The container for your usercontrol)

I think you are trying to retrieve your values before your usercontrol has
been restored. Surely you already know that when dynamically loading
controls the viewstate is not restored until the control is reloaded again.
If you can trap the event in your container and try retrieving the value
when this event fires, that should work for you. Otherwise try retrieving
the value right after the code where you are reloading your dynamic controls
fire, or any methods that fire afterwards.

The code you posted is still very little and I dont know on what method you
are loading your controls, and if that code is run after a postback etc nor
what the flow of your program is, but surely you should be on the right
track now


"Justin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> OK Alessandro,
>
> Here is the code you requested:
>
> // Load wizard placeholder with next user control
> wizardTabPlaceHolder = GetPlaceHolder(wizardTab); // This just finds the

placeholder in a tab control
> wizardTabPlaceHolder.Controls.Remove(currentUserCo ntrol); // I remove the

last visited control
> WizardUserControl nextControl =
> (WizardUserControl)Page.LoadControl(controlFileNam e); // Now I load

the control
> wizardTabPlaceHolder.Controls.Add(nextControl); // THen add it to the

placeholder.
>
> So, according to you there are some extra things that I need to do. What

properties do I need to set?
>
> At this point the only controls within this user control being loaded are

labels and textboxes. So as a user, when a user control is loaded I type in
text, then I click next. Now I want to be able to retreive the text in the
code behind of this control before I load the new control. The problem is
when I try to get the text the textboxes claim to be empty strings. This is
what I mean by no events firing. I guess its more of a timing thing, the
events are probably firing but I do not know when to catch them so that I
can get the text.
>
> The code above is called in my OnNext() method. I try to retreive the

text before the call to the above code.
>
> As far as bubbling the events up, I have not done that yet. I guess

because I do not know how to do it dynamically.
>
> Thanks for your quick response, I will look into the bubbling up.
>
> Justin
>
>



 
Reply With Quote
 
Justin
Guest
Posts: n/a
 
      01-27-2004
About the difference between a custom control and a user control, I guess I am confused and don't really know the difference. Maybe you can clear this up for me.

Thanks,

Justin
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Embedded <divs> with events: How to prevent the parent div's eventfrom being fired when the embedded div's event is fired? Num GG Javascript 2 11-17-2008 08:56 PM
No events are fired in child control Casper Hornstrup ASP .Net Building Controls 6 01-30-2004 09:05 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM
Catching events in web form fired by user control Nick Lewis ASP .Net 1 08-01-2003 12:01 PM



Advertisments