Batch Editing, Item Template, Validation Summary not displaying

1 posts, 0 answers
  1. Jason
    Jason avatar
    9 posts
    Member since:
    Aug 2017

    Posted 25 Aug 2017 Link to this post

    I Have a radgrid using batch edit mode, with insert & edit item templates.

    Grid is populated using OnNeedDataSource.

    I also have RadAjaxManager.

    There are RequiredFieldValidators in place to prevent fields being left empty. This shows an asterix next to each field that fails validation.

    ValidationSettings have been configured to set ValidationGroup.

    However, I am unable to get validation summary to display the 'ErrorMessage' to the user if a field is left empty and 'save' button clicked.

    I am using Telerik® UI for ASP.NET AJAX, v4.0.30319.

    Below is a very simple example to demonstrate the issue.

    Is there some configuration I have missed either in the grid or in RadAjaxManager?

    Thanks

    Jason

     

    aspx

    001.<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
    002. 
    003.<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    004. 
    005.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    006. 
    007.<html xmlns="http://www.w3.org/1999/xhtml">
    008.<head runat="server">
    009.    <title></title>
    010.    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
    011.</head>
    012.<body>
    013.    <form id="form1" runat="server">
    014.    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    015.        <Scripts>
    016.            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
    017.            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
    018.            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
    019.        </Scripts>
    020.    </telerik:RadScriptManager>
    021. 
    022.    <script type="text/javascript">
    023.    </script>
    024.     
    025.        <p>
    026.            Click on a cell/row to place it in edit mode.
    027.        </p>
    028.        <p>
    029.            Edit TextData, leave blank > Save: Validation summary should appear?
    030.        </p>
    031. 
    032.    <telerik:RadGrid ID="radGrid" runat="server" Width="100%" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" PageSize="12"
    033.                        OnNeedDataSource="radGrid_NeedDataSource"
    034.                        OnItemDataBound="radGrid_ItemDataBound"
    035.                        OnPreRender="radGrid_PreRender"
    036.                        OnBatchEditCommand="radGrid_BatchEditCommand"
    037.                        OnItemCreated="radGrid_ItemCreated"
    038.                        AllowAutomaticUpdates="True"
    039.                        AllowAutomaticInserts="True"
    040.                        ValidationSettings-EnableValidation="true">
    041.        <MasterTableView DataKeyNames="Id" CommandItemDisplay="Top" EditMode="Batch" AutoGenerateColumns="False">
    042.            <BatchEditingSettings EditType="Row"/>
    043.            <SortExpressions>
    044.                <telerik:GridSortExpression FieldName="Id" SortOrder="Ascending"/>
    045.            </SortExpressions>
    046.            <Columns>
    047.                <telerik:GridTemplateColumn UniqueName="Id" SortExpression="Id" HeaderText="ID">
    048.                    <ItemTemplate>
    049.                        <telerik:RadLabel runat="server" ID="Id" Text='<%# Eval("Id") %>'/>
    050.                    </ItemTemplate>
    051.                    <InsertItemTemplate>
    052.                        <telerik:RadTextBox runat="server" ID="Id" Text='<%# Eval("Id") %>'/>
    053.                        <asp:RequiredFieldValidator runat="server" ID="ValidateId" ControlToValidate="Id" EnableClientScript="True" ForeColor="Red" ErrorMessage="ID is required" Text="*" Display="Static"/>
    054.                    </InsertItemTemplate>
    055.                    <EditItemTemplate>
    056.                        <telerik:RadLabel runat="server" ID="Id" Text='<%# Eval("Id") %>'/>
    057.                    </EditItemTemplate>
    058.                </telerik:GridTemplateColumn>
    059. 
    060.                <telerik:GridTemplateColumn UniqueName="TextData" SortExpression="TextData" HeaderText="Description">
    061.                    <ItemTemplate>
    062.                        <telerik:RadLabel runat="server" ID="TextData" Text='<%# Eval("TextData") %>'/>
    063.                    </ItemTemplate>
    064.                    <InsertItemTemplate>
    065.                        <telerik:RadTextBox runat="server" ID="TextData" Text='<%# Eval("TextData") %>'/>
    066.                        <asp:RequiredFieldValidator runat="server" ControlToValidate="TextData" EnableClientScript="True" ForeColor="Red" ErrorMessage="Text data is required" Text="*" Display="Static" ValidationGroup="RadGridValidation"/>
    067.                    </InsertItemTemplate>
    068.                    <EditItemTemplate>
    069.                        <telerik:RadTextBox runat="server" ID="TextData" Text='<%# Eval("TextData") %>'/>
    070.                        <asp:RequiredFieldValidator runat="server" ControlToValidate="TextData" EnableClientScript="True" ForeColor="Red" ErrorMessage="Text data is required" Text="*" Display="Static" ValidationGroup="RadGridValidation"/>
    071.                    </EditItemTemplate>
    072.                </telerik:GridTemplateColumn>
    073. 
    074.                <telerik:GridTemplateColumn UniqueName="NumericData" SortExpression="NumericData" HeaderText="Selling Rate">
    075.                    <ItemTemplate>
    076.                        <telerik:RadLabel runat="server" ID="NumericData" Text='<%# Eval("NumericData") %>'/>
    077.                    </ItemTemplate>
    078.                    <InsertItemTemplate>
    079.                        <telerik:RadNumericTextBox runat="server" ID="NumericData" Type="Number" Value='<%# Eval("NumericData") %>' MinValue="0" > 
    080.                            <NumberFormat AllowRounding="false" KeepNotRoundedValue="false" DecimalDigits="5"/>
    081.                        </telerik:RadNumericTextBox>
    082.                        <asp:RequiredFieldValidator runat="server" ControlToValidate="NumericData" EnableClientScript="True" ForeColor="Red" ErrorMessage="Numeric data is required" Text="*" Display="Static" ValidationGroup="RadGridValidation"/>
    083.                    </InsertItemTemplate>
    084.                    <EditItemTemplate>
    085.                        <telerik:RadNumericTextBox runat="server" ID="NumericData" Type="Number" Value='<%# Eval("NumericData") %>' MinValue="0" > 
    086.                            <NumberFormat AllowRounding="false" KeepNotRoundedValue="false" DecimalDigits="5"/>
    087.                        </telerik:RadNumericTextBox>
    088.                        <asp:RequiredFieldValidator runat="server" ControlToValidate="NumericData" EnableClientScript="True" ForeColor="Red" ErrorMessage="Numeric Data is required" Text="*" Display="Static" ValidationGroup="RadGridValidation"/>
    089.                    </EditItemTemplate>
    090.                </telerik:GridTemplateColumn>
    091.            </Columns>
    092.        </MasterTableView>
    093.        <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
    094. 
    095.        <ValidationSettings EnableValidation="true" CommandsToValidate="PerformInsert,Update" ValidationGroup="RadGridValidation"></ValidationSettings>
    096.        <ClientSettings AllowKeyboardNavigation="true"></ClientSettings>
    097.    </telerik:RadGrid>
    098. 
    099.    <%-- Validation Summary --%>
    100.    <asp:ValidationSummary id="ValidationSummary" runat="server" ShowMessageBox="False" ShowSummary="True" DisplayMode="BulletList" HeaderText="Unable to commit changes:" ValidationGroup="RadGridValidation"/>
    101. 
    102.    <telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
    103.        <AjaxSettings>
    104.            <telerik:AjaxSetting AjaxControlID="radGrid">
    105.                <UpdatedControls>
    106.                    <telerik:AjaxUpdatedControl ControlID="radGrid" LoadingPanelID="RadAjaxLoadingPanel"/>
    107.                </UpdatedControls>
    108.            </telerik:AjaxSetting>
    109. 
    110.            <telerik:AjaxSetting AjaxControlID="ValidationSummary">
    111.                <UpdatedControls>
    112.                    <telerik:AjaxUpdatedControl ControlID="ValidationSummary" />
    113.                </UpdatedControls>
    114.            </telerik:AjaxSetting>
    115. 
    116.        </AjaxSettings>
    117.    </telerik:RadAjaxManager>
    118.    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel" runat="server" Modal="True" InitialDelayTime="250"/>
    119.    </form>
    120.</body>
    121.</html>

     

    c#

    using System;
    using System.Data;
    using Telerik.Web.UI;
    using System.Collections;
     
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
     
        protected void radGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            DataTable table = new System.Data.DataTable();
            table.Columns.Add("Id", typeof(int));
            table.Columns.Add("TextData", typeof(String));
            table.Columns.Add("NumericData", typeof(Double));
            table.Rows.Add(1, "A string", "10");
            table.Rows.Add(2, "A string", "20");
            table.Rows.Add(3, "A string", "30");
            table.Rows.Add(4, "A string", "40");
            table.Rows.Add(5, "A string", "50");
     
            radGrid.DataSource = table;
            radGrid.VirtualItemCount = table.Rows.Count;
        }
     
        protected void radGrid_PreRender(object sender, EventArgs e)
        {
     
        }
     
        protected void radGrid_ItemCreated(object sender, GridItemEventArgs e)
        {
     
        }
     
        protected void radGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
     
        }
     
        protected void radGrid_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
        {
            // update / insert commands from grid
            foreach (GridBatchEditingCommand command in e.Commands)
            {
                if ((command.Type == GridBatchEditingCommandType.Update))
                {
                    Hashtable newValues = command.NewValues;
     
                    String Id = newValues["Id"].ToString();
     
                    // Update record
                }
     
                if ((command.Type == GridBatchEditingCommandType.Insert))
                {
                    Hashtable newValues = command.NewValues;
     
                    String Id = newValues["Id"].ToString();
     
                    // Insert record
                }
            }
        }
    }

     

     

Back to Top