How do you capture User control events in the parent page

Discussion in 'ASP .Net' started by jw56578@gmail.com, Oct 6, 2004.

  1. Guest

    Hi,
    How would the following be accomplished. I have a parent aspx page,
    that dynamically loads 3 user controls (through LoadControl) depending
    on a certain criteria. I want the click of a button on one user
    control to make another user control invisible. How can the parent
    aspx page capture that click event so that it can know to do
    something. thanks
    , Oct 6, 2004
    #1
    1. Advertising

  2. Karl Seguin Guest

    The proper way to do is is to have the usercontrol raise an event the page
    can hook into. Something like this would go into your usercontrol:

    protected System.Web.UI.WebControls.Button hide;
    public event EventHandler onHideClick;

    private void hide_Click(object sender, System.EventArgs e) {
    if (this.onHideClick != null){
    this.onHideClick(this, e);
    }
    }


    and then your page could hook into the onHideClick event:


    uc1.onHideClick +=new EventHandler(uc1_onHideClick);

    private void uc1_onHideClick(object sender, EventArgs e) {
    //do stuff
    }

    Karl
    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    <> wrote in message
    news:...
    > Hi,
    > How would the following be accomplished. I have a parent aspx page,
    > that dynamically loads 3 user controls (through LoadControl) depending
    > on a certain criteria. I want the click of a button on one user
    > control to make another user control invisible. How can the parent
    > aspx page capture that click event so that it can know to do
    > something. thanks
    Karl Seguin, Oct 6, 2004
    #2
    1. Advertising

  3. Guest

    This doesn't appear to work. Whenever the button of the user control
    is clicked, this event is not recognized and the code is not executed
    in the click method, so the onHideClick event is not raised, and any
    other code in the button Click method is not called.

    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:<>...
    > The proper way to do is is to have the usercontrol raise an event the page
    > can hook into. Something like this would go into your usercontrol:
    >
    > protected System.Web.UI.WebControls.Button hide;
    > public event EventHandler onHideClick;
    >
    > private void hide_Click(object sender, System.EventArgs e) {
    > if (this.onHideClick != null){
    > this.onHideClick(this, e);
    > }
    > }
    >
    >
    > and then your page could hook into the onHideClick event:
    >
    >
    > uc1.onHideClick +=new EventHandler(uc1_onHideClick);
    >
    > private void uc1_onHideClick(object sender, EventArgs e) {
    > //do stuff
    > }
    >
    > Karl
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > <> wrote in message
    > news:...
    > > Hi,
    > > How would the following be accomplished. I have a parent aspx page,
    > > that dynamically loads 3 user controls (through LoadControl) depending
    > > on a certain criteria. I want the click of a button on one user
    > > control to make another user control invisible. How can the parent
    > > aspx page capture that click event so that it can know to do
    > > something. thanks
    , Oct 13, 2004
    #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. HP
    Replies:
    3
    Views:
    568
  2. Shawn Meyer

    Notify child control of events in parent control

    Shawn Meyer, Aug 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    142
    Shawn Meyer
    Aug 2, 2004
  3. Justin

    How do I capture events fired in child user controls?

    Justin, Jan 27, 2004, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    235
    Justin
    Jan 27, 2004
  4. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    353
    Chris
    Aug 30, 2005
  5. Jake Barnes
    Replies:
    15
    Views:
    183
    Thomas 'PointedEars' Lahn
    Feb 7, 2006
Loading...

Share This Page