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"/>

解决方案 »

  1.   

    我用ErrorMessage了,还是不显示啊
    其它那几个都可以,就CustomValidator不行,郁闷!
      

  2.   

    playing with the following sample code which is adapted from MSDN documentation:try to enter an odd number
    <%@ 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" />
          &nbsp;&nbsp;
          <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>
      

  3.   

    检查一下 自定义验证控件的IsValid 属性对吗?ServerValidation 起作用了吗?
      

  4.   

    借楼主宝地一用,我是用VB写的,但发现customvalidator中没有onservervalidationfunction,是版本问题吗?
    还有,我写的代码
    if Page.IsValid then
    lblOutput.Text = "Page is valid."
             else 
             lblOutput.Text = "Page is not valid!"
             end if
          else后的不执行。
    另外,是不是regularexpressionvalidator控件的errormessage信息是在输入数据不符合时才出现呢?