要显示的验证摘要:
<asp:ValidationSummary ID="ValidationSummary1" DisplayMode="BulletList"
EnableClientScript="true" runat="server" ValidationGroup="downloadGrp" />
必填字段验证器:
<asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
ControlToValidate="txtReasonForDownload"
ValidationExpression="^[\s\S]{0,500}$"
ValidationGroup="downloadGrp"
ErrorMessage="Max. 500 characters allowed!" runat="server">
</asp:RegularExpressionValidator><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtReasonForDownload" EnableClientScript="false"
ErrorMessage="Reason is required!" ValidationGroup="downloadGrp"
SetFocusOnError="true" Text="*"></asp:RequiredFieldValidator>
<asp:Label ID="Label2" runat="server" CssClass="error"
Text="Reason for Download:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"
ValidationGroup="downloadGrp"
Width="200px" MaxLength="500" Enabled="False"></asp:TextBox><br />
</ContentTemplate>
背后的代码:
protected void btnSubmitDownload_Click(object sender, EventArgs e)
{
string str1 = txtReasonForDownload.Text;
if (str1.Equals(string.Empty))
{
reqTxtReason.IsValid = false;
//Response.Write("<script> alert('Reason for Download is required!'); </script>");
} else { }
}
虽然启动了requiredfieldvalidator,但验证摘要不会显示验证。
答案 0 :(得分:2)
通过将验证摘要包含在另一个更新面板中并使用与其他更新面板相同的触发器来修复它