Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add javascript to a button

Status
Not open for further replies.

powerranger

Technical User
Feb 14, 2003
10
0
0
US
I have an asp button and would like to add a javascript to it. For example, I'd like to display a message Yes/No before submitting to another page. Thanks.
 
button1.Attributes.Add("OnClick", "javascript: return confirm('Are you sure you want to do this?');")
 
I've also found that if you use attributes.add you have to be carefull if you are using the validation controls with client side code enabled. Doing so also adds onclick events to buttons so you can end up with two onclick events, one of which will not work.
 
MichealPerry,

Thank you for reply. And you are right. When I originally posted my question, I had that problem. But I found a way to overcome the problem. Is it a bug in Asp.Net though if you have 2 onclick event and one of them is not working?
 
Doubt it. Its probably the HTML and Javascript standards that don't allow it. By the time you see the page asp has finished with it and it's all running client side.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top