views:

574

answers:

3

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

+1  A: 

You can easily add a client side Javascript click handler to an ASP button like this.

Button1.Attributes.Add("onclick", "alert('You clicked me!');");
Craig
Thanks for the answer +1....
Michael Kniskern
+4  A: 

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

e.g.

<button onclick="myHandler(this.ID)" />
Robert C. Barth
Thanks for the answer +1....
Michael Kniskern
+2  A: 

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();";
}
Michael Kniskern