Does RadDataForm support validation? I want to add RequiredFieldValidator and do a server side validation.
I am using DataForm with SelectMethod/UpdateMethod (Model Binding) and ValidationSummary.
I start the form in Edit Mode.
When I click Update and the field is empty, update method does not get called. There are no errors displayed on the page though. I can see that NameCustomValidator_ServerValidate method is called and it sets IsValid to false.
If the field is not empty then update method is called and works as expected.
I am using version 2017.2.711.45
I was able to successfully use validation with RadGrid.
My code...
I am using DataForm with SelectMethod/UpdateMethod (Model Binding) and ValidationSummary.
I start the form in Edit Mode.
When I click Update and the field is empty, update method does not get called. There are no errors displayed on the page though. I can see that NameCustomValidator_ServerValidate method is called and it sets IsValid to false.
If the field is not empty then update method is called and works as expected.
I am using version 2017.2.711.45
I was able to successfully use validation with RadGrid.
My code...
<asp:ValidationSummary ID="ValidationErrors" runat="server" /><telerik:RadDataForm ID="DataForm" runat="server" SelectMethod="GetDetails" UpdateMethod="UpdateDetails" ItemType="MyData" DataKeyNames="ID" OnPreRender="DataForm_PreRender" ItemPlaceholderID="itemPlaceholder1"> <LayoutTemplate> <div id="itemPlaceholder1" runat="server"></div> </LayoutTemplate> <ItemTemplate>Empty Read Only Page</ItemTemplate> <EditItemTemplate> <div> <telerik:RadButton ID="InsertButton1" runat="server" ButtonType="StandardButton" CommandName="Update" Text="Update" /> <telerik:RadButton ID="CancelButton1" runat="server" ButtonType="StandardButton" CausesValidation="False" CommandName="Cancel" Text="Cancel Changes" /> </div> <table> <tr> <td><telerik:RadLabel ID="NameLabel" runat="server" AssociatedControlID="NameTBox">Name:</telerik:RadLabel></td> <td> <telerik:TextBox ID="NameTBox" runat="server" Text="<%# BindItem.Name %>"></telerik:TextBox> <asp:RequiredFieldValidator ID="NameValidator" runat="server" ControlToValidate="NameTBox" ErrorMessage="Name is required" Text="!" Display="Static" /> <asp:CustomValidator ID="NameCustomValidator" runat="server" ControlToValidate="NameTBox" OnServerValidate="NameCustomValidator_ServerValidate" ErrorMessage="Name is required" Text="!" Display="Static" /> </td> </tr> </table> </EditItemTemplate></telerik:RadDataForm>
Start DataForm in edit mode
protected void DataForm_PreRender(object sender, EventArgs e){ // Display Edit mode when first loaded // Stay in Edit mode after update RadDataForm editForm = (RadDataForm) sender; if (editForm.Items.Count() > 0) { RadDataFormItem item = editForm.Items[0]; item.FireCommandEvent("Edit", ""); }}
This does get called.
protected void NameCustomValidator_ServerValidate(object source, ServerValidateEventArgs args){ args.IsValid = !string.IsNullOrEmpty(args.Value);}
Thanks