ASP.NET多个按钮button调用同一事件,区分是哪一button被点击

 前台aspx两个 button:

  <asp:Button ID="SaveAndBack" Text="保存并返回" runat="server" OnClick="btn_Save">"></asp:Button>

  <asp:Button ID="SaveAndAdd" Text="保存并新建" runat="server" OnClick="btn_Save"></asp:Button>

 后台aspx.cs的一个事件      

    protected void btn_Save(object sender, EventArgs e)

    {        

        if (((Button)sender).ID == "SaveAndBack")//关键是((Button)sender).ID 这个把sender转换成Button类型的,然后在获取按钮的ID

            {

                Response.Write("你点你的是保存并返回按钮");

            }

            else 

            {

                Response.Write("你点的保存并新建按钮");

            }

   } 

原文地址:https://www.cnblogs.com/tianliang/p/3116981.html