thirdknown
thirdknown

Reputation: 13

How can I access the button that was clicked?

I have code in jQuery:

// Group of buttons
$(".buttons").click(function() {

    // Do something with one button
    $(this). ...

});

I have an another program in C# Window Forms:

private void someButtons_Click(object sender, EventArgs e) {

    // How to know which button was clicked?
    // How to get an instance of that button?

}

Many thanks!

Upvotes: 0

Views: 77

Answers (2)

CountZero
CountZero

Reputation: 6389

   private void someButtons_Click(object sender, EventArgs e)
    {
        // How to get an instance of that button?
        Button myButton = ((Button)sender);

        // How to know which button was clicked?
        string buttonId = myButton.ID;
    }

Upvotes: 1

Ondrej Svejdar
Ondrej Svejdar

Reputation: 22054

You mean something like

private void someButtons_Click(object sender, EventArgs e) {
  var button = (Button)sender;
}

Upvotes: 2

Related Questions