OnClientClick fires 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: it seems that OnClientClick starts before ValidationGroup, because the JS function called in my OnClientClick closes my window.

Thus, the window closes, and the message "*" (error message) is displayed only when I re-open my window.

I need to check my ValidationGroup check! Thanks in advance for your help.

+6
source share
3 answers

Use Page_ClientValidate() , which checks client checks

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

Make Reasons Validation = "true" for the button.

+2
source

Use Page_ClientValidate() , which checks client checks

 <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="if(Page_ClientValidate()) CloseDialog();" OnClick="Button1_Click"/> 

In addition, you can also specify the Page_ClientValidate(validationGroup) check group if there are several checks on your page:

 <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="myGroup" OnClientClick="if(Page_ClientValidate('myGroup')) CloseDialog();" OnClick="Button1_Click" /> 
+2
source

Source: https://habr.com/ru/post/910790/


All Articles