How do you capture User control events in the parent page

J

jw56578

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
 
K

Karl Seguin

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
 
J

jw56578

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top