Required Field Validation Issue when Insert and Update forms are opened at the same time

1 Answer 79 Views
Grid
Amjad
Top achievements
Rank 1
Amjad asked on 22 Jun 2021, 09:05 PM

HI,

I can't submit the form when insert and update forms are opened simultaneously . I am trying to define separate validation groups for insert and update as it explained in the following link.

Radgrid perform validation only in edit or insert mode and not both. in UI for ASP.NET AJAX | Telerik Forums

But getting object reference error in the following code on PerformInsertButton and UpdateButton.

protected void RadGridFilePlanCEDMSFunctional_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                var rvValue = (RequiredFieldValidator)e.Item.FindControl("RadCboRetentionGracePeriodMonthValidator");

                if (e.Item is GridEditFormInsertItem)
                {
                    rvValue.ValidationGroup = "addRowValidation";
                    
                    ((e.Item as GridEditFormItem).FindControl("PerformInsertButton") as LinkButton).ValidationGroup = "FunctionalAddRowValidation";
                }
                else
                {
                    rvValue.ValidationGroup = "editRowValidation";
                    ((e.Item as GridEditFormItem).FindControl("UpdateButton") as LinkButton).ValidationGroup = "FunctionalEditRowValidation";
                }
            }
        }

 

Edit form template html is defined as follows...any help will be appreciated!

<%--EDIT MODE Controls--%>
                        <EditFormSettings EditFormType="Template">
                            <FormTemplate>
                                <table id="Table2" style="width: 100%; border-spacing: 2px; padding: 2px; border: 1px; border-collapse: collapse" class="table">
                                    <tr style="height: 10px">
                                        <td colspan="3"></td>
                                    </tr>
                                    <tr>
                                        <td style="width: 60px"></td>
                                        <td>
                                            <table id="Table3" style="width: 450px; border: 0px;">
                                                <tr>
                                                    <td style="vertical-align: middle">
                                                        <asp:Label ID="lblDocumentType" runat="server">Document Type:</asp:Label>
                                                    </td>
                                                    <td>
                                                        <telerik:RadComboBox ID="RadCboDocumentType" runat="server" RenderMode="Lightweight" Width="250px" Visible="true" TabIndex="1"
                                                            DataSourceID="dsDocumentTypes" DataTextField="DocumentTypename" DataValueField="DocumentTypeId" 
                                                            EmptyMessage="Select DocumentType" SelectedValue='<%# Bind("DocumentTypeId") %>'>
                                                        </telerik:RadComboBox>
                                                        <br />
                                                        
                                                    </td>
                                                </tr>
                                                <tr style="height: 5px">
                                                    <td colspan="2"></td>
                                                </tr>
                                                <tr>
                                                    <td style="vertical-align: middle">
                                                        <asp:Label ID="lblSite" runat="server">Site:</asp:Label>
                                                    </td>
                                                    <td>
                                                        <telerik:RadComboBox ID="RadCboSite" runat="server" RenderMode="Lightweight" Width="250px" Visible="true" TabIndex="2"
                                                            DataSourceID="dsSites" DataTextField="SiteName" DataValueField="SiteId" 
                                                            EmptyMessage="Select Site" SelectedValue='<%# Bind("SiteId") %>'>
                                                        </telerik:RadComboBox>
                                                        <br />
                                                        
                                                    </td>
                                                </tr>
                                                <tr style="height: 5px">
                                                    <td colspan="2"></td>
                                                </tr>
                                                <tr>
                                                    <td style="vertical-align: middle">
                                                        <asp:Label ID="lblRetYear" runat="server">Retention Year:</asp:Label>
                                                    </td>
                                                   <td>
                                                        <telerik:RadComboBox ID="RadCboRetentionYear" runat="server" RenderMode="Lightweight" Width="250px" TabIndex="3"
                                                            DataSourceID="dsRetentionYear" DataTextField="RetentionYear" SelectedValue='<%# Bind("RetentionYear") %>'
                                                            DataValueField="RetentionYear" EmptyMessage="Select Year">
                                                        </telerik:RadComboBox>
                                                        <br />
                                                        
                                                    </td>
                                                </tr>
                                                <tr style="height: 5px">
                                                    <td colspan="2"></td>
                                                </tr>
                                                <tr>
                                                    <td style="vertical-align: middle">
                                                        <asp:Label ID="lblRetMonth" runat="server">Retention Month:</asp:Label>
                                                    </td>
                                                    <td>
                                                        <telerik:RadComboBox ID="RadCboRetentionMonth" runat="server" RenderMode="Lightweight" Width="250px" TabIndex="4"
                                                            DataSourceID="dsRetentionMonth" DataTextField="RetentionMonth" SelectedValue='<%# Bind("RetentionMonth") %>'
                                                            DataValueField="RetentionMonth" EmptyMessage="Select Month">
                                                        </telerik:RadComboBox>
                                                        <br />
                                                        
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                        <td>
                                            <table id="Table1" style="padding: 1px; border-spacing: 1px; border: 0px;">
                                                <tr>
                                                    <td style="vertical-align: middle">
                                                        <asp:Label ID="lblRetGPMonth" runat="server">Retention Grace Period Month:</asp:Label>
                                                    </td>
                                                    <td>
                                                        <telerik:RadComboBox ID="RadCboRetentionGracePeriodMonth" runat="server" RenderMode="Lightweight" Width="268px" TabIndex="5"
                                                            DataSourceID="dsRetentionGracePeriodMonth" DataTextField="RetentionGracePeriodMonth" SelectedValue='<%# Bind("RetentionGracePeriodMonth") %>'
                                                            DataValueField="RetentionGracePeriodMonth" EmptyMessage="Select Month" >
                                                        </telerik:RadComboBox>
                                                        <br />
                                                        <asp:RequiredFieldValidator ID="RadCboRetentionGracePeriodMonthValidator" ControlToValidate="RadCboRetentionGracePeriodMonth"
                                                            runat="server" ErrorMessage="Retention Grace Period Month is a required field" Display="Dynamic" 
                                                            ForeColor="Red"></asp:RequiredFieldValidator>
                                                    </td>
                                                </tr>
                                                <tr style="height: 5px">
                                                    <td colspan="2"></td>
                                                </tr>
                                                <tr style="height: 5px">
                                                    <td colspan="2"></td>
                                                </tr>
                                                <tr>
                                                    <td style="vertical-align: top">
                                                        <asp:Label ID="lblComments" runat="server">Comments:</asp:Label>
                                                    </td>
                                                    <td>
                                                        <telerik:RadTextBox ID="RadTextBox" runat="server" TextMode="MultiLine" Rows="6" Columns="40" Wrap="true"
                                                            MaxLength="250" Text='<%# Bind("Comments") %>'>
                                                        </telerik:RadTextBox>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr style="height: 10px">
                                        <td colspan="3"></td>
                                    </tr>
                                    <tr>
                                        <td style="width: 60px"></td>
                                        <td style="text-align: center;" colspan="2">
                                            <telerik:RadButton RenderMode="Lightweight" ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Add" : "Update" %>'
                                                runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                            </telerik:RadButton>
                                            &nbsp;
                                            <telerik:RadButton RenderMode="Lightweight" ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                                CommandName="Cancel">
                                            </telerik:RadButton>
                                            &nbsp;
                                        </td>
                                    </tr>
                                    <tr style="height: 10px">
                                        <td colspan="3"></td>
                                    </tr>
                                    <tr>
                                        <td style="width: 60px"></td>
                                        <td class="insideHeader" colspan="2"></td>
                                    </tr>
                                    <tr style="height: 10px">
                                        <td colspan="3"></td>
                                    </tr>
                                </table>
                            </FormTemplate>
                        </EditFormSettings>
Amjad
Top achievements
Rank 1
commented on 24 Jun 2021, 12:47 PM

any response please?

1 Answer, 1 is accepted

Sort by
0
Accepted
Attila Antal
Telerik team
answered on 25 Jun 2021, 03:16 PM

Hi Amjad,

Check out our online demo Edit Form Types where we show how the serve bind expressions can be used to differentiate between Insert and Edit mode. Check the source code of the "EmployeeDetailsCS.ascx".

You can try the same approach using the ValidationGroup property:

<asp:Button runat="server" ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'  CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
    ValidationGroup='<%# (Container is GridEditFormInsertItem) ? "InsertValidationGroup" : "UpdateValidaionGroup" %>'>
</asp:Button>

 

Try this and let me know how it goes.

 

As a side note that, if you submit your request through a formal support ticket, we can guarantee 24 hours response time.

 

Regards,
Attila Antal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Amjad
Top achievements
Rank 1
commented on 30 Jun 2021, 07:51 PM | edited

Attila , your exampled helped , thanks!

i am not familiar about the formal support ticket process.
Doncho
Telerik team
commented on 05 Jul 2021, 12:31 PM

Hi Amjad,

The formal support ticket is a service for users with an active license. Since you have a valid license, you can open a support ticket from your Telerik account - https://www.telerik.com/account/ , by clicking on the GetTechnicalSupport option below the Support tab in the navigation bar:

Tags
Grid
Asked by
Amjad
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or