I want to prevent double click on my submit button. How do I do that? I tried different codes but nothing works at this time. Here is what I have for now:
And JavaScript for the click handler (assuming you can use jQuery):
function onSaveButtonClick(me) {
$(me).prev("div").show();
$(me).attr("disabled","disabled");
return true;
}
Inside this click handler, I will call client side validators and usually submit the form using $("form").submit(). If you rely on the button's default behavior for submitting the form be sure to return true from the handler.
The only option is to disable the button once the user clicks it or hit the enter button. But then you have to enable the button back on "asynchronous submit" or on validation errors in order to allow the user to submit the form again. You have already
achieved the solution in your code of disabling the submit button. now you have to place your code to enable it.
Please refer the following link for more options, but all of the options are directly or indirectly try to do the same thing you have done.
I want to prevent double click on my submit button. How do I do that? I tried different codes but nothing works at this time. Here is what I have for now:
The issue is related to the form.submit() method, after submit the form, the page reload and the same with the submit button, so the disabled attribute not working.
I suggest you could try to use the Asp.net Server Button control to submit the form, then use the Enabled property to disable the button. Code as below:
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
None
0 Points
3 Posts
Disable double click on submit button
Oct 12, 2016 07:44 PM|spider1212|LINK
Hi,
I want to prevent double click on my submit button. How do I do that? I tried different codes but nothing works at this time. Here is what I have for now:
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit" onclick="form.submit(); javascript=this.disabled = true;">
Contributor
6874 Points
1980 Posts
Re: Disable double click on submit button
Oct 12, 2016 08:50 PM|RichardY|LINK
You are close but I don't think the JavaScript in the onclick attribute is correct.
I like to show a progress spinner and either hide or disable the button. I use markup like this:
Css like this:
And JavaScript for the click handler (assuming you can use jQuery):
Inside this click handler, I will call client side validators and usually submit the form using $("form").submit(). If you rely on the button's default behavior for submitting the form be sure to return true from the handler.
None
0 Points
3 Posts
Re: Disable double click on submit button
Oct 13, 2016 07:06 PM|spider1212|LINK
Thanks RichardY
I tried this but it did not work for me.
Contributor
3310 Points
868 Posts
Re: Disable double click on submit button
Oct 13, 2016 07:23 PM|senthilwaits|LINK
spider1212,
The only option is to disable the button once the user clicks it or hit the enter button. But then you have to enable the button back on "asynchronous submit" or on validation errors in order to allow the user to submit the form again. You have already achieved the solution in your code of disabling the submit button. now you have to place your code to enable it.
Please refer the following link for more options, but all of the options are directly or indirectly try to do the same thing you have done.
http://www.the-art-of-web.com/javascript/doublesubmit/
Senthil Kumar Sundaram
Contributor
6874 Points
1980 Posts
Re: Disable double click on submit button
Oct 13, 2016 07:23 PM|RichardY|LINK
What did not work? Show me your relevant code and any errors.
All-Star
45489 Points
7008 Posts
Microsoft
Re: Disable double click on submit button
Nov 07, 2016 11:40 AM|Zhi Lv - MSFT|LINK
Hi spider1212,
The issue is related to the form.submit() method, after submit the form, the page reload and the same with the submit button, so the disabled attribute not working.
I suggest you could try to use the Asp.net Server Button control to submit the form, then use the Enabled property to disable the button. Code as below:
code behind:
Best regards,
Dillion