e.CommandArgument for asp button is not working

旧时模样 提交于 2019-11-29 09:08:48

@Tejs is correct in his comment, looks like you want something like this:

protected void allbuttons_Click(object sender, EventArgs e)
{
    var argument = ((Button)sender).CommandArgument;
}

Use

OnCommand = 

and

protected void allbuttons_Click(object sender, CommandEventArgs e) { }

Actually you don't need to pass the CommandArgument at all to know which button you pressed. You can get the ID of the button like below:

string id = ((Button)sender).ID;
abhijit

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;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!