I am trying to get the text value from a button that was clicked. In my head, it looks something like this:
private void button2_Click(object sender, EventArgs e)
{
string s = thisbutton.text
}
Select all the buttons and store in a variable using the querySelectorAll() method. let buttonList = document. querySelectorAll("button"); buttonList variable returns a nodeList that represents all the buttons.
Use the value property to get the value of a button in JavaScript.
The buttonPressed() callback function will have a returned event object which has all the data about the HTML element that is clicked on. To get the clicked element, use target property on the event object. Use the id property on the event. target object to get an ID of the clicked element.
How can I call SubGraphButton_Click(object sender, RoutedEventArgs args) from another method? private void SubGraphButton_Click(object sender, RoutedEventArgs args) { } private void ChildNode_Click(object sender, RoutedEventArgs args) { // call SubGraphButton-Click(). }
The object which fired the event is sender
, so:
private void button2_Click(object sender, EventArgs e)
{
string s = (sender as Button).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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With