use the ErrorMessage property:<asp:CustomValidator id="CustomValidator1"
ControlToValidate="Text1"
OnServerValidate="ServerValidation"
Display="Static"
ErrorMessage="Not an even number!"
ForeColor="green"
Font-Name="verdana"
Font-Size="10pt"
runat="server"/>
ControlToValidate="Text1"
OnServerValidate="ServerValidation"
Display="Static"
ErrorMessage="Not an even number!"
ForeColor="green"
Font-Name="verdana"
Font-Size="10pt"
runat="server"/>
其它那几个都可以,就CustomValidator不行,郁闷!
<%@ Page Language="C#" %>
<html>
<head>
<script runat="server">
void ValidateBtn_OnClick(object sender, EventArgs e)
{
if (Page.IsValid)
{
lblOutput.Text = "Page is valid.";
}
else
{
lblOutput.Text = "Page is not valid!";
}
}
void ServerValidation (object source, ServerValidateEventArgs arguments)
{ int i = int.Parse(arguments.Value);
arguments.IsValid = ((i%2) == 0); }
</script>
</head>
<body>
<form runat="server">
<h3>CustomValidator Example</h3>
<asp:Label id=lblOutput runat="server"
Text="Enter an even number:"
Font-Name="Verdana"
Font-Size="10pt" /><br>
<p>
<asp:TextBox id="Text1"
runat="server" />
<asp:CustomValidator id="CustomValidator1"
ControlToValidate="Text1"
OnServerValidate="ServerValidation"
Display="Static"
ErrorMessage="Not an even number!"
ForeColor="green"
Font-Name="verdana"
Font-Size="10pt"
runat="server"/>
<p>
<asp:Button id="Button1"
Text="Validate"
OnClick="ValidateBtn_OnClick"
runat="server"/><asp:ValidationSummary id="valSum"
DisplayMode="BulletList"
EnableClientScript="true"
HeaderText="You must enter a value in the following fields:"
runat="server"/> </form>
</body>
</html>
还有,我写的代码
if Page.IsValid then
lblOutput.Text = "Page is valid."
else
lblOutput.Text = "Page is not valid!"
end if
else后的不执行。
另外,是不是regularexpressionvalidator控件的errormessage信息是在输入数据不符合时才出现呢?