Pergunta

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.

Foi útil?

Solução

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);
}

Outras dicas

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...

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top