By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

How do you capture User control events in the parent page

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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/
<jw*****@gmail.com> wrote in message
news:d3**************************@posting.google.c om...
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

Nov 18 '05 #2

P: n/a
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:<Ou**************@TK2MSFTNGP10.phx.gbl>...
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/
<jw*****@gmail.com> wrote in message
news:d3**************************@posting.google.c om...
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

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.