Get the text value of the button that was clicked
Should be like this:
private void button2_Click(object sender, EventArgs e)
{
string s = this.button2.Text;
}
Just cast the sender Object to a Button Object and access the text attribute :
protected void btn_Click (object sender, EventArgs e){
Button btn = sender as Button;
string s= btn.Text
}
In every build in event handler there are 2 parameters sender
and e
.Sender
takes reference to that object which fires the event.The second parameter e
holds some information about the event(such as the location of pointer and other of this kind)
You need only bring it to Button type and get what information you want
The object which fired the event is sender
, so:
private void button2_Click(object sender, EventArgs e)
{
string s = (sender as Button).Text;
}