This is a migrated thread and some comments may be shown as answers.

Double server validate with CustomValidator in RadGrid

5 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Louis
Top achievements
Rank 1
Louis asked on 30 Oct 2015, 04:00 PM

Why when I'm using asp.net CustomValidator inside Insert/Edit ItemTemplate column of my RadGrid, the ServerValidate method is fired two times ?

I'm using telerik version 2015.3.930.45

Example:

Asp.net

 

<telerik:GridTemplateColumn UniqueName="ProductName" HeaderText="Product">
   <ItemTemplate><%# Eval("ProductName") %></ItemTemplate>
   <EditItemTemplate>
      <asp:TextBox Id="ProductNameText" Text='<%# Eval("ProductName") %>' runat="server"/>
      <asp:CustomValidator ID="ProductNameValidator" ControlToValidate="ProductNameText" Text="*" ErrorMessage="*" OnServerValidate="ProductNameValidator_OnServerValidate" runat="server"/>
   </EditItemTemplate>
</telerik:GridTemplateColumn>

 

C#

protected void ProductNameValidator_OnServerValidate(object source, ServerValidateEventArgs args)
{
   var newProductName = args.Value;
   args.IsValid = _myProducts.All(x => x.ProductName != newProductName);
}
 ​

5 Answers, 1 is accepted

Sort by
0
Louis
Top achievements
Rank 1
answered on 30 Oct 2015, 04:04 PM

Sorry for the confusion about my first sentence.

My question is, why "OnServerValidate" method is fired two times, when customValidator are inside RadGrid ?

0
Maria Ilieva
Telerik team
answered on 03 Nov 2015, 11:57 AM
Hello Louis,

I revise the presented column declaration and it looks absolutely correct without anything obvious that may lead to the described behavior. You can revise the online demo below where the OnServerValidate fires correctly and see what the difference in your case is:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/validation/defaultcs.aspx


Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Louis
Top achievements
Rank 1
answered on 03 Nov 2015, 02:14 PM

After a review of your exemple, it's also fired CustomValidation twice after user click on the "Insert"/"Update" button.

 It's seem to be a asp.net webform bugs with CustomValidator include inside a Templated List control.

 The way we correct this "double validation" is to override Page.Validate()

private bool _wasValidated;
protected override Validate() {
   if(!_wasValidated)
      base.Validate();
}

Thanks for you quick response to my thread

0
Louis
Top achievements
Rank 1
answered on 03 Nov 2015, 02:15 PM

in fact...

 

private bool _wasValidated;
protected override Validate() {
   if(!_wasValidated) {
      base.Validate();
      _wasValidated - true;
   }
}

0
Accepted
Maria Ilieva
Telerik team
answered on 04 Nov 2015, 11:54 AM
Hi,

Thank you for sharing your findings. I'm sure this will help other users that are facing the same behavior.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Louis
Top achievements
Rank 1
Answers by
Louis
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or