When using an asp.net application, I noticed that clicking several times on a button submits the request multiple times. To prevent this, I implemented a javascript function to ensure that the request is only submitted once. However, this solution caused the validation group to be suppressed, rendering the form validation components non-operational. Is there a way to prevent double-clicking while keeping the form validation active?
Below is the javascript function used to prevent double-clicking:
var submit = 0;
function CheckDouble() {
if (++submit > 1) {
return false;
}
}
Here is the button component in question:
<asp:Button ID="cmdSaveExpense" runat="server" Text="140" tooltip="Save and close" CausesValidation="true" ValidationGroup="NewExpense" CssClass="button2" OnClick="return CheckDouble()" />
The following validators are being suppressed:
<asp:RequiredFieldValidator ID="AmtRequired" runat="server" ControlToValidate="txtAmt" ErrorMessage="* An amount is required" ValidationGroup="NewExpense" Display="Dynamic" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="cboCat" ErrorMessage="" Text="* An expense type is required" ValidationGroup="NewExpense" Display="Dynamic" />