[ACCEPTED]-e.CommandArgument for asp button is not working-aspbutton
Accepted answer
@Tejs is correct in his comment, looks like 1 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) { }
0
Actually you don't need to pass the CommandArgument 2 at all to know which button you pressed. You 1 can get the ID of the button like below:
string id = ((Button)sender).ID;
You can assign command-text to your buttons 1 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;
}
}
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.