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

DAValidation not working in ListView

5 Answers 75 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Jonathan Copelton
Top achievements
Rank 1
Jonathan Copelton asked on 26 Jan 2014, 08:19 PM
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>




















5 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 30 Jan 2014, 09:50 AM
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.
0
Jonathan Copelton
Top achievements
Rank 1
answered on 31 Jan 2014, 11:11 AM
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.
0
Marin
Telerik team
answered on 31 Jan 2014, 03:15 PM
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.
0
Jonathan Copelton
Top achievements
Rank 1
answered on 03 Feb 2014, 10:11 AM
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
0
Marin
Telerik team
answered on 05 Feb 2014, 09:23 AM
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.
Tags
ListView
Asked by
Jonathan Copelton
Top achievements
Rank 1
Answers by
Marin
Telerik team
Jonathan Copelton
Top achievements
Rank 1
Share this question
or