Loading

【转】解决CustomValidator控件不能验证控件值为空的问题(asp.net1.1测试环境)

不要指定CustomValidator   控件的ControlToValidate就行了,这样在提交的时候回进行验证  
   
  代码如下:  
  ---------------------------------  
  <%@   Page   Language="C#"   AutoEventWireup="True"   %>  
   
  <html>  
  <head>  
  </head>  
  <body>  
   
        <form   runat="server"   id="Form1"   >  
              <asp:TextBox   id="Text1"    
                        runat="server"   />  
   
              <asp:CustomValidator   id="CustomValidator1"  
                        ClientValidationFunction="ClientValidate"  
                        Display="Static"  
                        ErrorMessage="不能为空!"  
                        ForeColor="green"  
                        Font-Name="verdana"    
                        Font-Size="10pt"  
                        runat="server"/>  
  <br/>    
              <asp:Button   id="Button1"  
                        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>   
    
 

posted @ 2008-10-27 21:53  .net's  阅读(833)  评论(1编辑  收藏  举报