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

Loosing the changes on WebUserControl editform of RadGrid on validation failure.

3 Answers 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Devi
Top achievements
Rank 1
Devi asked on 17 Jan 2019, 04:41 PM

I am using WebUserControl as the editform of radgrid and setting usercontrol fields with e.Item.DataItem values in ItemDataBound. If the validation fails on performInsert or Update ItemCommand, I am setting e.Cancel to true. Since, I am setting the DataItem values in the ItemDataBound, I am loosing my changes in the user control. Is there any way, I can check validation failure in the ItemDataBound before setting the values of usercontrol?

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 22 Jan 2019, 09:27 AM
Hi Devi,

This could be a suitable scenario for CustomValidator:
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.customvalidator?view=netframework-4.7.2

Instead of executing your validation logic during the Update/PerformInsert commands, you can do it beforehand using the ServerValidate event handler of the validator. Here is a sample configuration:
<asp:DropDownList ID="ddlApproval" runat="server">
    <asp:ListItem>PENDING</asp:ListItem>
    <asp:ListItem>APPROVED</asp:ListItem>
</asp:DropDownList>
<asp:CustomValidator ID="CustomValidator1" runat="server" Display="Static" ForeColor="Red"
    ErrorMessage="You have to select APPROVE" ValidateEmptyText="true"
    ControlToValidate="ddlApproval" OnServerValidate="CustomValidator1_ServerValidate">
</asp:CustomValidator>
VB:
Protected Sub CustomValidator1_ServerValidate(source As Object, args As ServerValidateEventArgs)
    args.IsValid = args.Value = "APPROVED"
End Sub

I hope this will prove helpful.


Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Devi
Top achievements
Rank 1
answered on 22 Jan 2019, 03:01 PM

I tried CustomValidator, but I had the ServerValidate  event handler in the user control's c# code.  Even though I had same ValidationGroup for the CustomValidator and the submit button and set args.IsValid false, the code in the ItemCommand was executed after the validation. Because of the postback, usercontrol fields were set to the original values in the ItemDataBound.

I fixed this issue by storing the updated value in a static member variable on validation failure and setting the usercontrol field with it if we are binding after validation failure. 

0
Eyup
Telerik team
answered on 25 Jan 2019, 01:47 PM
Hi Devi,

I'm glad you've managed to resolve the issue, however, the issue with the CustomValidator is strange, indeed. If you want you can open a formal support thread to send us a very basic runnable web site sample reproducing the issue so we can further investigate it locally from our end.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Devi
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Devi
Top achievements
Rank 1
Share this question
or