OnClientClick fired before ValidationGroup

user1173169 picture user1173169 · Mar 15, 2012 · Viewed 11.9k times · Source

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

Answer

PraveenVenu picture PraveenVenu · Mar 15, 2012

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" />