[ACCEPTED]-e.CommandArgument for asp button is not working-aspbutton

Accepted answer
Score: 41

@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;
}
Score: 9

Use

OnCommand = 

and

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

0

Score: 2

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;
Score: 1

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;
    }
}

More Related questions