acessing an id from object sender
-
I've created buttons automatically based on rows of information. When someone pushes the button I call the eventhandler button1_Click(object sender, EventArgs e). Is there anyway to tell what the name of the button is? I'm using c# in asp.net. When debugging i can see the clientid but cant get it from sender.
-
I've created buttons automatically based on rows of information. When someone pushes the button I call the eventhandler button1_Click(object sender, EventArgs e). Is there anyway to tell what the name of the button is? I'm using c# in asp.net. When debugging i can see the clientid but cant get it from sender.
Cast the sender object to a Button:
Button myButton = sender as Button;
if(myButton != null)
{
string name = myButton.Name;
} -
Cast the sender object to a Button:
Button myButton = sender as Button;
if(myButton != null)
{
string name = myButton.Name;
}That did it thanks. Since im using asp i used myButton.id instead of name. Thanks again.