要显示的验证摘要:
<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,但验证摘要不显示验证。