e.CommandArgument for asp button is not working

前端 未结 4 640
孤独总比滥情好
孤独总比滥情好 2020-12-18 19:41

I am developing a asp.net application using C#. I created an .aspx page and placed four buttons on different locations on the page. On server side, I want to use just one cl

4条回答
  •  青春惊慌失措
    2020-12-18 20:19

    You can assign command-text to your buttons as follows:

    protected void allbuttons_Click(Object sender, CommandEventArgs e) {
        switch(e.CommandName) {
            case "Button1":
                Message.Text = "You clicked the First button";
                break;
            case "Button2":
                Message.Text = "You clicked the Second button";
                break;
            case "Button3":
                Message.Text = "You clicked Third button";
                break;
            case "Button4":
                Message.Text ="You clicked Fourth button";
                break;
        }
    }
    

提交回复
热议问题