Can I bubble up a button click event of a button in master page to be handled by an event handler in the aspx page ?
A:
You can rebroadcast the event. Declare a new corresponding event in your master page, such as HelpClicked
and then aspx pages that use this master can subscribe to the event and handle it appropriately. The master can also take a default action if there are no subscribers (or use an EventArgs with a Handled property or something like that).
Sam
2010-01-29 03:43:19
+1
A:
You can expose the event handler and hookup to it, like this:
In the master:
public event EventHandler ButtonClick
{
add { ButtonThatGetsClicked.Click += value; }
remove { ButtonThatGetsClicked.Click -= value; }
}
In the page:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
((MyMasterType)Master).ButtonClick += MyHandler;
}
private void MyHandler(object sender, EventArgs e)
{
//Do Something
}
Also, you can avoid the Master type cast and have it already appear in intellisense as your Master's type by using the @MasterType directive in the aspx markup.
Nick Craver
2010-01-29 03:45:21
A:
This post might help.
http://cherupally.blogspot.com/2010/02/bubbling-up-events-from-user-control-to.html
Kiran Cherupally
2010-03-31 11:23:27