I have the following jQuery code to prevent double-clicking a button. It is working fine. I use Page_ClientValidate() to guarantee a double click only if the page is valid. [If there are verification errors, the flag should not be set, since there is no return to the server]
Is there a better way to prevent a second click on a button before the page loads?
Is it possible to set the flag isOperationInProgress = yesIndicator only if the page causes a isOperationInProgress = yesIndicator to the server? Is there a suitable event for it that will be called before the user can click the button a second time?
Note I am looking for a solution that does not require any new API
Note This question is not a duplicate. Here I try to avoid using Page_ClientValidate() . I am also looking for an event where I can move the code so that I do not need to use Page_ClientValidate()
Note There is no ajax in my script. The ASP.Net form will be sent to the server synchronously. The button click event in javascript is only intended to prevent a double click. Form submission synchronously using ASP.Net.
Existing code
$(document).ready(function () { var noIndicator = 'No'; var yesIndicator = 'Yes'; var isOperationInProgress = 'No'; $('.applicationButton').click(function (e) {
References
- Validator causes incorrect behavior for double-click validation
- Use Page_IsValid or Page_ClientValidate () (for client-side events)
Note by @Peter Ivan in the links above:
calling page_ClientValidate () can lead to an overly intrusive page (multiple warnings, etc.).
javascript jquery
Lijo May 23 '13 at 1:22 pm 2013-05-23 13:22
source share