DAValidation not working in ListView

6 posts, 0 answers
  1. Jonathan Copelton
    Jonathan Copelton avatar
    4 posts
    Member since:
    Sep 2009

    Posted 26 Jan 2014 Link to this post

    Hi.  I'm trying to get the DAValidation control to render client side errors with the telerik ListView control in either InsertItemTemplate or EditItemTemplate.  At the minute nothing is rendered when I break one of my entity rules.  The DAValidation control works fine within templates in a standard asp FormView template but not with Telerik controls.  Any help would be greatly appreciated.  I have provided a sample ListView below:


    <telerik:RadListView ID="frm" runat="server" OnPreRender="frm_PreRender" >

    <ItemTemplate>
    <asp:Label ID="lbl" runat="server" Text='<%#: Bind("Forename") %>' />
    </ItemTemplate>

    <EditItemTemplate>

    <dav:MetadataSource ID="MetadataSource1" runat="server" ObjectType="<%$ Code: typeof(LE.Entities.Employee) %>">
    </dav:MetadataSource>
    <dav:DataAnnotationsValidator ID="davName" runat="server" ForeColor="Red" ValidationGroup="PersonalDetails" MetadataSourceID="MetadataSource1" ControlToValidate="txtName"
    ObjectProperty="Name" />
    <asp:TextBox ID="txtName" runat="server" ></asp:TextBox>

    </EditItemTemplate>
    </telerik:RadListView>




















  2. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 30 Jan 2014 Link to this post

    Hi,

    I tested the provided sample configuration for ListView and it appears to work well with DAValidation. Attached is a sample runnable page where you can check the correct behavior. The validation rules are: that the FirstName field is required and it's length should be 10 or less. When you press the "Save" button it will display a red message if any of the rules are broken.
    Here is also the ListView configuration that worked on my side:
    <telerik:RadListView ID="ListView1" runat="server" OnNeedDataSource="ListView1_NeedDataSource">
                    <ItemTemplate>
                        <asp:Label ID="lbl" runat="server" Text='<%#: Bind("FirstName") %>' />
                        <asp:Button ID="btnEdit" runat="server" Text="Edit" Visible='<%# ListView1.EditIndexes.Count <= 0 %>' CommandName="Edit" Width="70px"></asp:Button>
                        <br />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <dav:MetadataSource ID="MetadataSource1" runat="server" ObjectType="<%$ Code: typeof(Employee) %>">
                        </dav:MetadataSource>
                        <dav:DataAnnotationsValidator ID="davName" runat="server" ForeColor="Red" ValidationGroup="PersonalDetails"
                            MetadataSourceID="MetadataSource1" ControlToValidate="txtName"
                            ObjectProperty="FirstName" />
                        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                        <asp:Button Text="Save" runat="server" ID="btnSave" OnClick="btnSave_Click" ValidationGroup="PersonalDetails" />
                    </EditItemTemplate>
                </telerik:RadListView>

    I hope this helps.

    Kind Regards,
    Marin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jonathan Copelton
    Jonathan Copelton avatar
    4 posts
    Member since:
    Sep 2009

    Posted 31 Jan 2014 in reply to Marin Link to this post

    The solution provided displays an error after a page post back. I'm trying to generate client side errors.  This normally happens when I tab off a textbox using the DAValidation control.  Any help with this would be much appreciated.
  5. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 31 Jan 2014 Link to this post

    Hi,

    Any kind of validation that you can achieve with the DAValidation control outside of the RadListView (or by using a FormView) can be applied in the same way when the controls are inside the ListView. 
    I am attaching the modified page: click "Edit" button to go in edit mode then delete the text in the first textbox and tab to the second textbox - it will fire the client-side validation and display the error message. The behavior is the same as with the FormView control.
    I hope this helps. Let me know if there is any particular configuration in the code where the validation inside the ListView does not behave the same way as with FormView.

    Kind Regards,
    Marin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  6. Jonathan Copelton
    Jonathan Copelton avatar
    4 posts
    Member since:
    Sep 2009

    Posted 03 Feb 2014 in reply to Marin Link to this post

    Hi thanks for your help with this.  I got this working now.  My problem was that the project I was using did not include

    <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />

    in the ScriptManager.  Anyway it's working now.

    Many Thanks
  7. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 05 Feb 2014 Link to this post

    Hi,

    I'm glad to hear you resolved the problem. Let us know if you have any other questions.

    Regards,
    Marin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017