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

Validating fields in a FormTemplate

5 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 04 Aug 2016, 08:19 PM

I can't seem to trigger my validators within my FormTemplate on my grid. I can't find any examples of this either. Is it possible? Do I have to resort to using client side JS to manually trigger them on the submit?

 

<ValidationSettings EnableValidation="true" CommandsToValidate="PerformInsert,Update" />

<FormTemplate>
                                    <table>
                                        <tr>
                                            <td>Milestone Name: </td>
                                            <td>
                                                <asp:TextBox runat="server" Text='<%# Bind("Name") %>' ID="txtMilestoneName" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtMilestoneName" 
                                                    runat="server" ErrorMessage="* - Required Field"  Display="Dynamic" ValidationGroup="Milestone"
                                                    ForeColor="Red" Font-Bold="true"></asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Pipline: </td>
                                            <td><asp:DropDownList runat="server" SelectedValue='<%# Bind("PipelineID") %>' ID="ddlPipline"
                                                ItemType="ONEOK.BusinessData.BusinessObjects.Pipeline"
                                            DataTextField="Name" DataValueField="PipelineID" SelectMethod="getPipelines" AppendDataBoundItems="true">
                                                <asp:ListItem Text="Select..." Value="0" />
                                            </asp:DropDownList>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="ddlPipline"
                                                    ErrorMessage="* - Required Field" InitialValue="" ForeColor="Red" Font-Bold="true"></asp:RequiredFieldValidator>

                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Threshold Value: </td>
                                            <td>
                                                <asp:TextBox runat="server" Text='<%# Bind("MilestoneThresholdValue") %>' ID="txtMilestoneThresholdValue" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtMilestoneThresholdValue" runat="server" ErrorMessage="* - Required Field" ForeColor="Red" Font-Bold="true"></asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Latitude: </td>
                                            <td>
                                                <asp:TextBox runat="server" Text='<%# Bind("Latitude") %>' ID="txtLatitude" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="txtLatitude" runat="server" ErrorMessage="* - Required Field" ForeColor="Red" Font-Bold="true"></asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Longitude: </td>
                                            <td>
                                                <asp:TextBox runat="server" Text='<%# Bind("Longitude") %>' ID="txtLongitude" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" ControlToValidate="txtLongitude" runat="server" ErrorMessage="* - Required Field" ForeColor="Red" Font-Bold="true"></asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td valign="top">Photo: </td>
                                            <td>
                                                <telerik:RadBinaryImage ID="rbiMilestone" DataValue='<%# Eval("Photo") %>' runat="server" />
                                                <telerik:RadAsyncUpload ID="radMilestoneImage" AllowedFileExtensions="jpg,jpeg,png,gif" runat="server" 
                                                     
                                                    AutoAddFileInputs="false" Localization-Select="Upload Image"></telerik:RadAsyncUpload>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Milestone Information: </td>
                                            <td><telerik:RadEditor ID="radEventLongDesc" Content='<%# Bind("MilestoneInformation") %>' ContentAreaCssFile="~/content/rte.css" runat="server" Width="500px" ToolbarMode="PageTop" BackColor="White"></telerik:RadEditor></td>
                                        </tr>
                                        <tr>
                                            <td align="center" colspan="2">
                                                <asp:Button ID="btnUpdate" CausesValidation="true" ValidationGroup="Milestone" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                                    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>&nbsp;
                                                <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                                    CommandName="Cancel"></asp:Button>
                                            </td>
                                        </tr>
                                    </table>
                                </FormTemplate>

5 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 09 Aug 2016, 12:31 PM
Hi Michael,

Try removing the ValidationGroup property from the Button and everything should be fine.
I am also sending a sample web site sample with similar implementation as a reference.

Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Michael
Top achievements
Rank 1
answered on 09 Aug 2016, 12:59 PM
There are several different validation groups on this page. Won't they all be submitted with any submit button if I do that?
0
Eyup
Telerik team
answered on 12 Aug 2016, 07:55 AM
Hello Michael,

Yes, you are correct. If you want to prevent that, you should set ValidationGroup for the entire edit form controls, including the validation ones, similar to the attached web site sample.

Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Michael
Top achievements
Rank 1
answered on 12 Aug 2016, 02:04 PM
So if I'm using a wizard and a form in each step, with the formtemplates in grids within each step, validation for those isn't going to work?
0
Eyup
Telerik team
answered on 17 Aug 2016, 12:15 PM
Hi Michael,

If the buttons of the wizard aren't of type submit or if their ValidationGroup is not the same as the form elements, it is expected for the validation not to fire.

Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Michael
Top achievements
Rank 1
Share this question
or