How do I capture events fired in child user controls?

Discussion in 'ASP .Net Web Controls' started by Justin, Jan 27, 2004.

  1. Justin

    Justin Guest

    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
    Justin, Jan 27, 2004
    #1
    1. Advertising

  2. Justin

    Eran Amitai Guest

    Justin, I know there are user controls and custom controls. What are custom
    user controls?

    Eran

    "Justin" <> wrote in message
    news:...
    > 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, Jan 27, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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, Jan 27, 2004
    #3
  4. 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" <> wrote in message
    news:...
    > 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(currentUserControl); // I remove the

    last visited control
    > WizardUserControl nextControl =
    > (WizardUserControl)Page.LoadControl(controlFileName); // 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
    >
    >
    Alessandro Zifiglio, Jan 27, 2004
    #4
  5. Justin

    Justin Guest

    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
    Justin, Jan 27, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Rodriguez
    Replies:
    23
    Views:
    1,116
    David Schwartz
    Dec 9, 2003
  2. Casper Hornstrup

    No events are fired in child control

    Casper Hornstrup, Jan 29, 2004, in forum: ASP .Net Building Controls
    Replies:
    6
    Views:
    185
    Jeffrey Tan[MSFT]
    Jan 30, 2004
  3. Replies:
    0
    Views:
    202
  4. David Boike

    Child controls in Composite Controls not firing events

    David Boike, Aug 7, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    312
    David Boike
    Aug 7, 2003
  5. Richard Lionheart

    Events fired by custom controls not caught

    Richard Lionheart, Oct 31, 2005, in forum: ASP .Net Web Controls
    Replies:
    7
    Views:
    161
    Richard Lionheart
    Nov 3, 2005
Loading...

Share This Page