i have some requiredfieldvalidators.
when i have a regular asp:button, all goes well.
But, now we’ve implemented the OnClientClick event on the submit button:
<asp:Button ID="SaveButton" runat="server" Text="Save changes" OnClick="SaveButton_Click" OnClientClick="return SubmitForm2();" />
the submitform2 method is implemented to set the caption of the submitbutton (please wait) and to disable it to avoid double clicking.
function SubmitForm2() {
$("#SaveButton").attr("disabled", "true");
$("#SaveButton").val("Please wait...");
__doPostBack("SaveButton", "");
return true;
}
but what we see is when we run this code, the clientsidevalidators are not called.
is that because we run the __doPostBack ourselves, that otherwise other code (to check the validators) is fired?
Yes – post-back is happening because you are doing
__doPostBackby yourself. Once you disable the button, submit behavior by the button gets supressed blocking validators.One of better implementation of desired functionality could be to set the js-timer for short duration for disabling button and then for longer duration for enabling the button. For example,
Even better implementation can be achieved by using validator’s client side API. Here’s one such simpler but better modification of previous one,