Bubbling Event in Composite controls

Discussion in 'ASP .Net Building Controls' started by Nidhee, Jul 31, 2004.

  1. Nidhee

    Nidhee Guest

    Hi Everyone,


    I am building a composite server control. I have defined an event for
    my child control with Custom Event Arguments. I am using the bubbling
    method to access the child control's events in the Parent control.
    Still, my child control is not raising the event. What am I missing?
    Following is the code snippet:

    //Child control code

    public class ChildClass: System.Web.UI.WebControls.WebControl,
    ISerializable, IPostBackEventHandler, INamingContainer
    {
    public event CustomEventHandler DoubleClick;
    protected override void Render(HtmlTextWriter writer){ ... }

    #region IPostBackEventHandler Members
    public void RaisePostBackEvent(string eventArgument)
    {
    CustomEventArgs cusArgs = new CustomEventArgs(this.PKID);
    if (DoubleClick != null)
    {
    DoubleClick(this, cusArgs);
    RaiseBubbleEvent(this, cusArgs);
    }
    }

    #endregion

    #region CustomEventArgs class
    //CustomEventArgs class
    public class CustomEventArgs: EventArgs
    {
    public CustomEventArgs(int PKID)
    {
    this.PKID = PKID;
    }

    public int PKID;
    } //end of class RectangleEventArgs
    #endregion
    }

    //Parent control code
    public class ParentClass : System.Web.UI.WebControls.WebControl,
    IPostBackEventHandler

    public event CustomEventHandler GetCustomProperties;
    protected override void CreateChildControls() { ... }

    protected override bool OnBubbleEvent(object source, EventArgs args)
    {
    bool handled = false;
    if(GetCustomProperties != null)
    if(args is CustomEventArgs)
    {
    CustomEventArgs e = (CustomEventArgs)args;
    GetCustomProperties(this, e);
    handled = true;
    }
    return handled;
    }
     
    Nidhee, Jul 31, 2004
    #1
    1. Advertising

  2. "Nidhee" <> wrote in message
    news:...
    > Hi Everyone,
    >
    >
    > I am building a composite server control. I have defined an event for
    > my child control with Custom Event Arguments. I am using the bubbling
    > method to access the child control's events in the Parent control.
    > Still, my child control is not raising the event. What am I missing?


    Did you try to catch the event directly, without bubbling?
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Aug 1, 2004
    #2
    1. Advertising

  3. Nidhee

    Nidhee Guest

    "John Saunders" <> wrote in message news:<#vVLA$>...
    > "Nidhee" <> wrote in message
    > news:...
    > > Hi Everyone,
    > >
    > >
    > > I am building a composite server control. I have defined an event for
    > > my child control with Custom Event Arguments. I am using the bubbling
    > > method to access the child control's events in the Parent control.
    > > Still, my child control is not raising the event. What am I missing?

    >
    > Did you try to catch the event directly, without bubbling?


    Thanks for your response.
    Yes, I tried to catch the Child's event directly. The event is working
    fine when the child is not contained in the parent control. But the
    instance of the child control in the parent control does not Raise a
    Postback event. Looks like the parent control needs to handle the
    event somehow. I am not able to figure out, how.

    Nidhee
     
    Nidhee, Aug 2, 2004
    #3
  4. "Nidhee" <> wrote in message
    news:...
    > "John Saunders" <> wrote in message

    news:<#vVLA$>...
    > > "Nidhee" <> wrote in message
    > > news:...
    > > > Hi Everyone,
    > > >
    > > >
    > > > I am building a composite server control. I have defined an event for
    > > > my child control with Custom Event Arguments. I am using the bubbling
    > > > method to access the child control's events in the Parent control.
    > > > Still, my child control is not raising the event. What am I missing?

    > >
    > > Did you try to catch the event directly, without bubbling?

    >
    > Thanks for your response.
    > Yes, I tried to catch the Child's event directly. The event is working
    > fine when the child is not contained in the parent control. But the
    > instance of the child control in the parent control does not Raise a
    > Postback event. Looks like the parent control needs to handle the
    > event somehow. I am not able to figure out, how.


    Pardon me, I meant did you try to directly catch the event in the parent?

    Right now, you are not receiving the bubbled event. This could either be
    because the child is not raising the event, or because the child is raising
    the event but bubbling isn't working. If you are able to directly catch the
    child event, you will know that the problem is with bubbling.

    When I say catch the event directly, I mean something like the following:

    protected override void CreateChildControls()
    {
    ...
    Button btn = new Button();
    btn.Text = "Button text";
    btn.Click += new EventHandler(btn_Click);

    Controls.Add(btn);
    ...
    }

    private void btn_Click(object sender, EventArgs e)
    {
    Page.Trace.Write("Button click caught");
    }
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Aug 2, 2004
    #4
    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. sleigh
    Replies:
    1
    Views:
    2,694
    sleigh
    Feb 12, 2004
  2. Nathan Sokalski

    Event Bubbling and the ItemCommand Event

    Nathan Sokalski, May 29, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    407
    Nathan Sokalski
    May 29, 2006
  3. Javi

    Composite Controls and Bubbling events

    Javi, Jul 8, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    167
  4. Nathan Sokalski

    Event Bubbling and the ItemCommand Event

    Nathan Sokalski, May 29, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    142
    Nathan Sokalski
    May 29, 2006
  5. Nathan Sokalski

    Event Bubbling and the ItemCommand Event

    Nathan Sokalski, May 29, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    143
    Nathan Sokalski
    May 29, 2006
Loading...

Share This Page