也就是我想把客户端验证函数灵活一点,在CustomValidator的客户端函数中传入长度参数。问一下该如何做?找了半天,网上只有msdn的相关例子

解决方案 »

  1.   

    pass them as attributes for the customvalidator, for example, CustomValidator1.Attributes["len"] = "123";then in your client side functionfunction ClientValidate(source, arguments)
    {
      var s = source.len; 
      ...
    }
      

  2.   

    大哥,这样好像又麻烦了干脆我换种方法问:CustomValidator只能用这个函数吗function ClientValidate(source, arguments),里面参数不能增加吗?如果不能,还是那么麻烦着吧
      

  3.   

    问题是CustomValidator的客户端验证函数不是由你直接调用的,所以你想传递参数,要么这么做,要么用RegisterStartupScript或Page的其他Register*函数生成客户端的全局变量
      

  4.   

    如果你想最大的灵活性,你就只好自己输出form的验证函数了
      

  5.   

    今天经过反复试验.才得出如何利用CustomValidator来验证textbox的长度.
    首先,如思归老兄所说,在page_load添加CustomValidator1.Attributes["len"] = "123";即定义长度值.然后 写客户端验证函数<script language="javascript">
    function DataLength(source, arguments)
    {
    var len = source.length;
    if(Form1.TextBox.value.length<=len)
    {
    arguments.IsValid = true;
    }
    else
    {
    arguments.IsValid = false;
    }
    }
    </script>注有2处不同var len = source.length;获取长度范围if(Form1.TextBox.value.length<=len)这里有没有其他写法.就不知道了.有研究更深的兄弟告诉一下.