Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine which ASP.NET button was clicked using Javascript

What is the best way to determine which ASP.NET button was clicked on a single page using JavaScript?

like image 327
Michael Kniskern Avatar asked Nov 27 '25 22:11

Michael Kniskern


2 Answers

Add a client-side onclick handler to each button pointing to the same function?

e.g.

<button onclick="myHandler(this.ID)" />
like image 77
Robert C. Barth Avatar answered Nov 30 '25 11:11

Robert C. Barth


I just the set the OnClientClick event handler for the button with the JavaScript function I wanted executed when the button was clicked during the Page_Load event.

protected void Page_Load(object sender, EventsArgs e)
{
    MyButton.OnClientClick = "MyJavaScriptMethod();";
}
like image 38
Michael Kniskern Avatar answered Nov 30 '25 12:11

Michael Kniskern



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!