Remember, always have server side validations for double or duplicate processing. This technique is a client-side script that presents a user friendly way of disabling the button once clicked.
// Click Once on Purchase:
StringBuilder sbJS = new StringBuilder();
sbJS.Append("if (typeof(Page_ClientValidate) == 'function') { ");
sbJS.Append("if (Page_ClientValidate() == false) { return false; }} ");
sbJS.Append("this.value = 'Please wait...';");
sbJS.Append("this.src = '/Images/purchase_grey.gif';");
sbJS.Append("this.disabled = true;");
sbJS.Append("this.alt = 'Please wait...';");
sbJS.Append(Page.ClientScript.GetPostBackEventReference(imgbtnPurch, ""));
sbJS.Append(";");
imgbtnPurch.Attributes.Add("onclick", sbJS.ToString());
Love coding!
9 comments:
Briliiant! iv tried lots of code but this one works fine on ajax platform.
I have a problem with this code, it doesn't take effect the first time the button is clicked. It only seems to work after the page has been posted back. Any advice?
Where are you adding this code snippet? For example, did you try using it in Page_Load event? I'm guessing you are adding this on a postback event rather than initial load itself.
Hope this helps,
Excellent Solution.. Helps me very much. Thank you.
Awesome easy solution for a once click button, thank much!
Thank you so much. This is simple, elegant, and AWESOME code!!
Thank u very much ! it help's me lot. simply AWESOME......
You can also do it without the c# code. See here:
http://lawo.wordpress.com/2010/05/14/disable-button-after-click-with-confirmation-clientside/
Excellent! I have tried several approaches one can find, but this one is one actually works with no conflict with jquery and AJAX
Thank You!
Post a Comment