October 4, 2011

Multiple Button controls to work from a single Function


default.aspx
<asp:ButtonID="Button1"runat="server"Text="Button1"
OnCommand="Button_Command"CommandName="btn1"/>
<asp:ButtonID="Button2"runat="server"Text="Button2"
OnCommand="Button_Command"CommandName="btn2"/>





default.aspx.cs

protected voidButton_Command(Object sender,
System.Web.UI.WebControls.CommandEventArgs e)
{
switch(e.CommandName)
{
case("btn1"):
Response.Write("Button1 was clicked");
break;
case("btn2"):
Response.Write("Button2 was clicked");
break;
}
}

No comments:

Post a Comment