The Button_Command event (C#) : Events « ASP.net Controls « ASP.NET Tutorial






<%@ 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>








3.41.Events
3.41.1.Get event dispacher from event argument
3.41.2.The Button_Command event (VB.net)
3.41.3.The Button_Command event (C#)
3.41.4.Two types of events for the button (C#)
3.41.5.Two types of events for the button (VB)
3.41.6.EventHandler