I realise this question has been asked but none of the answers worked for my project.
I have a button that when clicked calls an API, so there is a 1 second delay.
I have tried several things nothing works.
btnSave.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnSave, null) + ";");
Even that does nothing.
This is the one I found works in all cases.
Prevent Double Click .Please add below code in your aspx page.
Prevent Double Click .Please add below code in your aspx page
This solution is simple and effective. On your button include this code:
And wherever you want your JavaScript - e.g. At the bottom of your page:
You can prevent double-clicking using this code:
So you can use
btnSave_Click
to call your API.Usually I have a lot of
Validators
in myPage
: settingValidator.SetFocusOnError = True
I can run this code to reenable save button if a validation failed.Most of the above suggestions failed to work for me. The one that did work was the following by tezzo:
Simpler still, rather than using the above in the code-behind, just use the following:
UseSubmitBehavior="false" is the key.