验证摘要不显示在网格视图中

本文关键字:网格 视图 显示 验证 | 更新日期: 2023-09-27 18:24:59

我使用了两个验证摘要,但它们并没有显示错误消息。虽然必需的字段验证器正在工作,但验证摘要并没有显示,所以我的问题是
我想显示错误消息。

<div>
        <asp:GridView ID="GrdHiringResource" runat="server" AutoGenerateColumns="False" DataKeyNames="hiring_resource_id"
            OnRowCancelingEdit="GrdHiringResource_RowCancelingEdit" OnRowDataBound="GrdHiringResource_RowDataBound"
            OnRowEditing="GrdHiringResource_RowEditing" OnRowUpdating="GrdHiringResource_RowUpdating"
            OnRowCommand="GrdHiringResource_RowCommand" ShowFooter="True" OnRowDeleting="GrdHiringResource_RowDeleting"
            BackColor="White" BorderColor="#D1B271" BorderStyle="None" BorderWidth="1px"
            CellPadding="4">
            <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" BorderColor="#D1B271" />
            <RowStyle BackColor="White" ForeColor="#000000" BorderColor="#D1B271" />
            <Columns>
                <asp:TemplateField HeaderText="Hiring Resource name" SortExpression="Location_name">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtName" runat="server" Text='<%# Eval("hiring_resource_name") %>' ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="ReqName" ValidationGroup="update" Display="Dynamic"
                            runat="server" ControlToValidate="txtName" ErrorMessage="Please enter ResourceName">*</asp:RequiredFieldValidator>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtNewName" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="ReqNewname" runat="server" ValidationGroup="save"
                            ControlToValidate="txtNewName" ErrorMessage="Please enter ResourceName" Display="Dynamic"
>*</asp:RequiredFieldValidator>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("hiring_resource_name") %>' ></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Description">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtdescription" runat="server"  TextMode="MultiLine" Text='<%# Bind("description") %>'></asp:TextBox>
                          <asp:RequiredFieldValidator ID="Reqdescription" ValidationGroup="update" Display="Dynamic"
                            runat="server" ControlToValidate="txtdescription" ErrorMessage="Please enter Description">*</asp:RequiredFieldValidator>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtNewdescription" runat="server" TextMode="MultiLine" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="ReqNewDescription" runat="server" ControlToValidate="txtNewdescription"
                            ErrorMessage="Please enter Description" ValidationGroup="save" Display="Dynamic">*</asp:RequiredFieldValidator>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("description") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="" ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                            Text="Update" ValidationGroup="update"></asp:LinkButton>
                        <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                            Text="Cancel"></asp:LinkButton>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="true" CommandName="AddNew"
                            Text="Add New" ValidationGroup="save"></asp:LinkButton>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                            Text="Edit"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField HeaderText="" ShowDeleteButton="True" ShowHeader="True" />
            </Columns>
            <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" BorderColor="#D1B271" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" BorderColor="#D1B271" />
            <HeaderStyle BackColor="#D1B271" Font-Bold="True" ForeColor="#000000" HorizontalAlign="Center"
                BorderColor="#D1B271" />
        </asp:GridView>
    <asp:ValidationSummary runat="server"  ID="update" DisplayMode="BulletList" ShowMessageBox="true"
ShowSummary="false" EnableClientScript="false"/>
    <asp:ValidationSummary runat="server"  ID="save" DisplayMode="BulletList" ShowMessageBox="true"
ShowSummary="false" EnableClientScript="false"/>
      </div>

验证摘要不显示在网格视图中

我认为这就是问题所在,请将此属性设置为true

  EnableClientScript="true" 

更新:遇到问题,是validationGroup,请将validationGroup属性添加到validationSummary或从RequiredFieldValidators 中删除validationGroup

<asp:ValidationSummary runat="server"  ID="update" DisplayMode="BulletList" ValidationGroup="update"/>
<asp:ValidationSummary runat="server"  ID="save" DisplayMode="BulletList" ValidationGroup="save"/>

我建议您使用验证组。此外,为EditItemTemplate验证器和Footer验证器创建单独的ValidationGroup。这将防止一个发射另一个。此参考资料也将帮助您:

参考:验证组

尝试将ShowSummary设置为"true"或ShowMessageBox设置为"true"

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.validationsummary.aspx