Thursday, November 20, 2008

Basic: Adding JavaScript Confirmations to an ASP.Net Button

Adding Javascript generated confirmations to your ASP.Net buttons is easy, but I always seem to forget how to do and my first and second guesses are usually wrong. So instead of using google to find the answer next time, I will use google in a new way (my blog) to store the answer. Ok here goes.

  btnCancel.Attributes.Add ( "onclick",
"javascript:if(confirm('" + CancelMessage + "')){do stuff;return true;}else{return false;}" );

No comments: