Search code examples
c#javascriptasp.netvalidationgroup

OnClientClick fired before ValidationGroup


This is the code i'm using:

            <telerik:RadTextBox ID="txtTitre" runat="server" Skin="Windows7" Width="250">
            </telerik:RadTextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
                ForeColor="Red" ControlToValidate="txtTitre" ValidationGroup="validationincident"></asp:RequiredFieldValidator>

And my ASP button:

        <asp:Button ID="Button1" runat="server" Text="Soumettre ce ticket" OnClick="Button1_Click"
            OnClientClick="CloseDialog()" UseSubmitBehavior="false" ValidationGroup="validationincident" />

My problem is it seems OnClientClick is fired before ValidationGroup since the JS function called in my OnClientClick Closes my window.

So the window closes and the "*" (error message) is only displayed when i reopen my window.

I need my ValidationGroup to be checked first! Thanks in advance for your help


Solution

  • Use Page_ClientValidate() which checks the client validations

    <asp:Button ID="Button1" runat="server" Text="Soumettre ce ticket" OnClick="Button1_Click"
                OnClientClick="if(Page_ClientValidate()) CloseDialog();" UseSubmitBehavior="false" ValidationGroup="validationincident" />