[英]fire asp.net customValidator
My problem is , i have an input password that had a custumValidator when i modified the value of password i check if the password not contain the name. 我的问题是,当我修改了密码的值时,我有一个输入密码具有custumValidator,我检查密码是否不包含名称。 I need to fire the same customvalidator(client validation) when i edit also the field name: howa can i do this:
当我还编辑字段名称时,我需要触发相同的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" />
<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>
Try adding this: 尝试添加以下内容:
EDIT : 编辑 :
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.