Search code examples
c#asp.netvb.netwebformsvalidationsummary

Overriding OnClientClick causing validation to fire multiple times


I'm trying to prevent a form from being submitted multiple time. It uses a validation summary so I am overriding the OnClientClick event for the submit button. It works as expected, the window showing the list of errors is being loaded multiple times.

<asp:Button ID="btnSubmit" runat="server" 
            Text="Submit" 
            CausesValidation="False" 
            ValidationGroup="vgApplication" 
            OnClientClick=" if ( Page_ClientValidate() ) { this.value='Submitting..'; this.disabled=true; }" 
  />

Solution

  • The problem was that I have multiple ValidationGroups on my form. So I had to specify which ValdationGroup to run by passing in the name to Page_ClientValidate().

    <asp:Button ID="btnSubmit" runat="server" 
                Text="Submit" 
                CausesValidation="False" 
                OnClientClick=" if ( Page_ClientValidate('vgApplication') ) { this.value='Submitting..'; this.disabled=true; }" 
      />