【问题标题】:fire asp.net customValidator触发 asp.net customValidator
【发布时间】:2013-08-01 20:33:10
【问题描述】:

我的问题是,当我修改密码的值时,我有一个输入密码,它有一个 custumValidator 我检查密码是否不包含名称。当我还编辑字段名称时,我需要触发相同的 customvalidator(客户端验证): 我该怎么做:

     <form id="Form1" runat="server">

      <h3>CustomValidator ServerValidate Example</h3>

      <asp:Label id="Message"  
           Text="Enter an even number:" 
           Font-Name="Verdana" 
           Font-Size="10pt" 
           runat="server"/>

      <p>

      <asp:TextBox id="name" 
           runat="server" />
<asp:TextBox id="password" 
           runat="server" />

      &nbsp;&nbsp;

      <asp:CustomValidator id="CustomValidator1"
           ControlToValidate="password"
           ClientValidationFunction="ClientValidate"
           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"/>

   </form>
</body>
</html>

<script language="javascript"> 
   function ClientValidate(source, arguments)
   {
        // here i will implement :if source contains name
            arguments.IsValid = true;
         else {
            arguments.IsValid = false;
        }
   }
</script>

【问题讨论】:

    标签: asp.net validation customvalidator


    【解决方案1】:

    尝试添加这个:

    编辑

    <form id="Form1" runat="server">
      <script type="text/javascript">
        function ValidatePassword (source, arguments){
          // Gets the name field
          var nameField = document.getElementById('<%= name.ClientId %>');
          // using indexOf since contains does not exist in js.
          // If it is not found it will return -1
          arguments.IsValid = (arguments.Value.indexOf(nameField.value) == -1);
        }
      </script>
      <asp:TextBox id="name" 
           runat="server" />
      <asp:TextBox id="password" 
           runat="server" />
    
      <asp:CustomValidator id="CustomValidator1"
           ControlToValidate="password"
           ClientValidationFunction="ValidatePassword"
           ErrorMessage="Password should not contain your user name!"
           runat="server"/>
    
      <asp:Button id="Button1"
           Text="Validate" 
           OnClick="ValidateBtn_OnClick" 
           runat="server"/>
    
    </form>
    

    【讨论】:

      猜你喜欢
      • 2010-12-11
      • 2023-03-05
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-25
      相关资源
      最近更新 更多