How to prevent button double-click on ASP.NET page
Solution
Add following code to Page_load. This code prevents button double-click on client-side but still executes code at server-side:
VB.Net
btnSave.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnSave, Nothing) + ";")
C#
btnSave.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnSave, null) + ";");
it gives this error:
ReplyDelete"Microsoft JScript runtime error: Sys.ParameterCountException: Parameter count mismatch."
Could you paste full code?
ReplyDeleteIts Working nice for me, But problem crops up when I have RequiredFieldValidators on my Page
ReplyDeletesame error:"Microsoft JScript runtime error: Sys.ParameterCountException: Parameter count mismatch."
ReplyDeletei face same problem
DeleteThanks. It Works great for me.
ReplyDeletegood work... it worked for me
ReplyDeletethanks.
thanks. it works for me...
ReplyDeleteWorks!!!
ReplyDeleteFor the error thing: Change it "onclick" to "onClientClick" (basically system complaining about multiple object for "onclick" property)
For adding the validation, can be like this: (in VB.NET)
btnEvaluateNext.Attributes.Add("onclientclick", "if(Page_ClientValidate('ValidationGroup')){this.disabled = true; + ClientScript.GetPostBackEventReference(btnEvaluateNext, Nothing) + ";}")
and actually without the __dopostback thing it will still work:
btnEvaluateNext.Attributes.Add("onclientclick", "if(Page_ClientValidate('vgRating')){this.disabled = true; }")
Sorry, it works last Friday but not now.. I don't even change anything. Weird and I just get rid of this disable stuff...
ReplyDeleteWorked in C# =)
ReplyDeleteReally helpful .. Thanks tommi
ReplyDeleteAwe a simple answer to an aggravating problem. THANKS!
ReplyDeletei get err :Uncaught ReferenceError: ClientScript is not defined
ReplyDeleteI have same, but issue is still I need to click twice on link button.
ReplyDeleteWell I have tried many things, but could not resolve the issue. I have more than 2 update panel and link buttons are on the update panel, but update panel are not place within update panel. Any help or suggestion are highly appreciated.
It works for me well. In my code I have several validations. But After implementing below. If I leave any mandatory field and click on Save button. The validation message box pops up twice. first it shows a message box "Please fill the fields" and after clicking on "OK" the message is displayed again....Any idea how to rectify this?
ReplyDeleteButtonSave.Attributes.Add("onclick", "if(Page_ClientValidate('ValidatePage')){this.disabled = true;} " + ClientScript.GetPostBackEventReference(ButtonSave, null) + ";");
works great, thanks !!
ReplyDeleteVery simple... works great!!
ReplyDeleteThanks! worked for me :)
ReplyDeleteThanks bro ...
ReplyDeleteworked for me too...
good job.
Thank you very much, its working
ReplyDeleteThank you.
ReplyDeleteThanks work fine
ReplyDeleteAwesome Works Great!! I have been searching for past two days for an answer and wouldn't you know it would be a one liner that would do the trick. Thanks Much!
ReplyDeleteWorked for me (VB.net)! Thank you!!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI've seen other solutions and yours seems easiest. Working good.
ReplyDeleteIn vb.net there shouldn't be a plus(+) sign, it should be an ampersand-->&.
ReplyDeleteYou guys could be getting errors because of that.
Thanks.
ReplyDeleteIt's working for me ...
Thanks.
ReplyDeleteIt works for me
btnSave.Attributes.Add("onclick",ClientScript.GetPostBackEventReference(btnSave, "")+ ";this.value='Processing...';this.disabled = true; this.style.display='block';");
ReplyDeleteIf i am using this one how can i perform client side validation?
It works for me
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI found this article easy to understand and very helpful. Can’t wait to see the other posts. Thank you for sharing!
ReplyDeleteIts working
ReplyDelete