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

4 posts, 0 answers
  1. Devi
    Devi avatar
    2 posts
    Member since:
    Aug 2017

    Posted 17 Jan Link to this post

    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?

  2. Eyup
    Admin
    Eyup avatar
    3644 posts

    Posted 22 Jan Link to this post

    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.
  3. Devi
    Devi avatar
    2 posts
    Member since:
    Aug 2017

    Posted 22 Jan in reply to Eyup Link to this post

    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. 

  4. Eyup
    Admin
    Eyup avatar
    3644 posts

    Posted 25 Jan Link to this post

    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.
Back to Top