Events in server controls

Discussion in 'ASP .Net Building Controls' started by I am Sam, Feb 16, 2008.

  1. I am Sam

    I am Sam Guest

    I need to write a composite control where a click event in the
    parent(container) class fires an event in a child control. How is this
    possible? ie clicking a button in the parent control performs an action on a
    child control.
     
    I am Sam, Feb 16, 2008
    #1
    1. Advertising

  2. I am Sam

    Teemu Keiski Guest

    Hi,

    you could access the child control in button's click event? Or if it's
    something internal in the child control, it should be informed somehow that
    the Click occurred, maybe it could wire up to an event of the parent control
    which the parent exposes publicly?

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net

    "I am Sam" <> wrote in message
    news:...
    >I need to write a composite control where a click event in the
    > parent(container) class fires an event in a child control. How is this
    > possible? ie clicking a button in the parent control performs an action
    > on a
    > child control.
     
    Teemu Keiski, Mar 16, 2008
    #2
    1. Advertising

  3. I am Sam

    I am Sam Guest

    The solution is very simple really. You can for example write the following:
    protected override void CreateChildControls()
    {
    ImageButton someImageButton=new ImageButton();
    someImageButton.Click += new ImageClickEventHandler(ImageButton_Click);
    this.Controls.Add(someImageButton);
    }

    protected void ImageButton_Click(object sender, ImageClickEventArgs e)
    {
    do something..;
    }

    within your custom control. You only want to bubble events when you want to
    expose your event in the containing page.

    "Teemu Keiski" wrote:

    > Hi,
    >
    > you could access the child control in button's click event? Or if it's
    > something internal in the child control, it should be informed somehow that
    > the Click occurred, maybe it could wire up to an event of the parent control
    > which the parent exposes publicly?
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    > "I am Sam" <> wrote in message
    > news:...
    > >I need to write a composite control where a click event in the
    > > parent(container) class fires an event in a child control. How is this
    > > possible? ie clicking a button in the parent control performs an action
    > > on a
    > > child control.

    >
    >
    >
     
    I am Sam, Mar 16, 2008
    #3
    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. newbye
    Replies:
    0
    Views:
    586
    newbye
    Jul 6, 2006
  2. =?Utf-8?B?cml2YWxAbmV3c2dyb3Vwcy5ub3NwYW0=?=

    Linking events from controls, when the controls have been created

    =?Utf-8?B?cml2YWxAbmV3c2dyb3Vwcy5ub3NwYW0=?=, Jul 16, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    599
    =?Utf-8?B?cml2YWxAbmV3c2dyb3Vwcy5ub3NwYW0=?=
    Jul 16, 2007
  3. SevDer
    Replies:
    2
    Views:
    1,312
    Walter Wang [MSFT]
    Nov 13, 2007
  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:
    323
    David Boike
    Aug 7, 2003
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    388
    Chris
    Aug 30, 2005
Loading...

Share This Page