3

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

4 Answers 4

4

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

e.g.

<button onclick="myHandler(this.ID)" />
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

1

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

Button1.Attributes.Add("onclick", "alert('You clicked me!');");

Comments

1
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.

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.