不要指定CustomValidator   控件的ControlToValidate就行了,这样在提交的时候回进行验证  
   
  代码如下:  
  ---------------------------------  
  <%@   Page   Language="C#"   AutoEventWireup="True"   %>  
   
  <html>  
  <head>  
  </head>  
  <body>  
   
        <form   runat="server"     >  
              <asp:TextBox      
                        runat="server"   />  
   
              <asp:CustomValidator    
                        ClientValidationFunction="ClientValidate"  
                        Display="Static"  
                        ErrorMessage="不能为空!"  
                        ForeColor="green"  
                        Font-Name="verdana"    
                        Font-Size="10pt"  
                        runat="server"/>  
  <br/>    
              <asp:Button    
                        Text="Validate"    
                        runat="server"/>  
        </form>  
       
  </body>  
  </html>  
   
  <script   language="javascript">  
  <!--  
  function   ClientValidate(sender,   args)  
  {  

  var txtvalue = document.getElementById("TextBox1");
  if(txtvalue .value.length<=0)  
  {  
  args.IsValid   =   false;  
  }else{  
  args.IsValid   =   true;  
  }  
  }  
  //   -->  
  </script>   
    
 

相关文章:

  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
猜你喜欢
  • 2021-05-17
  • 2022-12-23
  • 2021-12-03
  • 2021-08-03
  • 2021-08-26
  • 2021-08-12
  • 2021-11-15
相关资源
相似解决方案