Reputation: 893
I have one master page with two content page each content page has submit button:
<asp:ImageButton runat="server" type="image" id="buttonSubmit" name="buttonSubmit"
alt="ImageButton 1" src="images/button.png" OnClientClick="PreventExitPop=true"/>
I want to be able to create one onclick
event on the masterpage.cs
:
protected void buttonSubmit_Click(object sender, EventArgs e)
{
//
}
and attach the two buttons from the content pages to this event.
<asp:ImageButton runat="server" type="image" id="buttonSubmit" name="buttonSubmit"
alt="ImageButton 1" src="images/button.png"
onclick="buttonSubmit_Click"
OnClientClick="PreventExitPop=true"/>
The problem is that each content page knows only his code file and not the masterpage.cs
.
Upvotes: 1
Views: 244
Reputation: 4768
You could write event handlers for each control and in those handlers you call a event handler method in the master page
protected void buttonSubmit_Click(object sender, EventArgs e)
{
((MasterType) this.Master).buttonSubmit_Click(sender, e);
}
Upvotes: 1
Reputation: 2083
i think you should not be able to do that, and its not true that a event handler bind to two separate event at all... i think, if you can, you should create your button on master page... if you can not, you should have two event handler for these buttons, but u can create a method and in this method do everything you want, and call this method from two defined handlers...
Upvotes: 0