Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
What is the best way to determine which ASP.NET button was clicked on a single page using JavaScript?
Add a client-side onclick handler to each button pointing to the same function?
e.g.
<button onclick="myHandler(this.ID)" />
Add a comment
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();"; }
You can easily add a client side Javascript click handler to an ASP button like this.
Button1.Attributes.Add("onclick", "alert('You clicked me!');");
ScriptManager.RegisterStartupScript(btnDelSentMailMulti, this.GetType(), "script", "alert('Exchange password is empty.Please check.');", true);
Call this code in .cs of your aspx page. Replace with your values.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.