I have three buttons which have different names and have a same click Event.
How can distinguish one click from other click, as depending on the button selected I need perform various actions.
Thank you
You can use the sender argument passed to your event handler.
Assuming you have three buttons with IDs Button1, Button2 and Button3:
protected void Buttons_Click(object sender, EventArgs e)
{
if (sender == Button1) {
// Do something...
} else if (sender == Button2) {
// Do something else...
} else if (sender == Button3) {
// Etc.
}
}
In you click method you'll need a switch/select statement. Then you could use the sender object like the c# example below.
public buttons_click(Object sender, Event e)
{
var buttonText = sender.Text;
switch(buttonText)
{
case "button1":
//code
break;
case "button2":
ect...
}
}
Hope this helps.