我正在使用两个验证摘要,但它们没有显示错误消息。虽然必填字段验证器正在运行,但验证摘要没有显示,所以我的问题是。
我想显示错误消息。
<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>
答案 0 :(得分:1)
我建议您使用验证组。此外,为EditItemTemplate验证程序和页脚验证程序创建单独的ValidationGroups。这将阻止一个人开火。此参考文章也可以帮助您:
答案 1 :(得分:1)
尝试设置ShowSummary =“true”或ShowMessageBox =“true”
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.validationsummary.aspx
答案 2 :(得分:1)
我认为这是问题所在,将此属性设置为true
EnableClientScript="true"
更新:遇到问题,它是validationGroup,要么将validationGroup属性添加到validationSummary,要么从RequiredFieldValidators中删除valiationGroup
<asp:ValidationSummary runat="server" ID="update" DisplayMode="BulletList" ValidationGroup="update"/>
<asp:ValidationSummary runat="server" ID="save" DisplayMode="BulletList" ValidationGroup="save"/>