Pass the sender object to the button, and then you can get all the properties.
Button clickedButton = (Button)sender;
Also tell me which method is more efficient? Calling different methods with different button presses or when calling the same method (if the functionality of each button is the same).
If the functionality is the same, then it is better to have one event, since you do not need to copy the code. Remember the DRY principle.
Consider the following example:
protected void Button1_Click(object sender, EventArgs e) { Button clickedButton = sender as Button; if (clickedButton == null) // just to be on the safe side return; if (clickedButton.ID == "Button1") { } else if(clickedButton.ID == "Button2") { } }
Habib
source share