Mega Code Archive

 
Categories / ASP.Net Tutorial / ASP Net Controls
 

The Button_Command event (C#)

<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server">     protected void Button_Command(Object sender,        System.Web.UI.WebControls.CommandEventArgs e)     {         switch (e.CommandName)         {             case ("DoSomething1"):                 Response.Write("Button 1 was selected");                 break;             case ("DoSomething2"):                 Response.Write("Button 2 was selected");                 break;         }     } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">     <title>Buttons</title> </head> <body>     <form id="form1" runat="server">     <div>         <asp:Button ID="Button1"                      Runat="server" Text="Button 1"                      OnCommand="Button_Command"                      CommandName="DoSomething1" />         <asp:Button ID="Button2"                      Runat="server"                      Text="Button 2"                      OnCommand="Button_Command"                      CommandName="DoSomething2" />         </div>     </form> </body> </html>