Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   How do I capture events fired in child user controls? (http://www.velocityreviews.com/forums/t772442-how-do-i-capture-events-fired-in-child-user-controls.html)

Justin 01-27-2004 02:46 AM

How do I capture events fired in child user controls?
 
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

Eran Amitai 01-27-2004 11:20 AM

Re: How do I capture events fired in child user controls?
 
Justin, I know there are user controls and custom controls. What are custom
user controls?

Eran

"Justin" <anonymous@discussions.microsoft.com> wrote in message
news:B23A7AA9-F674-4C4D-B1AA-030248330A30@microsoft.com...
> 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




Alessandro Zifiglio 01-27-2004 03:13 PM

Re: How do I capture events fired in child user controls?
 
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" <anonymous@discussions.microsoft.com> wrote in message
news:B23A7AA9-F674-4C4D-B1AA-030248330A30@microsoft.com...
> 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




Alessandro Zifiglio 01-27-2004 07:44 PM

Re: How do I capture events fired in child user controls?
 
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" <anonymous@discussions.microsoft.com> wrote in message
news:CF3C83C4-08D2-4697-933E-CAAF030EFADD@microsoft.com...
> 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
>
>




Justin 01-27-2004 09:51 PM

Re: How do I capture events fired in child user controls?
 
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


All times are GMT. The time now is 08:07 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.