David Munsa
David Munsa

Reputation: 893

attach two ASP.NET content page buttons to one masterpage event

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

Answers (2)

Mikael Engver
Mikael Engver

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

Amir Sherafatian
Amir Sherafatian

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

Related Questions