Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在ASP.NET中同时使用CustomValidator和RequiredFieldValidator?_Javascript_Asp.net_Client Side Validation - Fatal编程技术网

Javascript 如何在ASP.NET中同时使用CustomValidator和RequiredFieldValidator?

Javascript 如何在ASP.NET中同时使用CustomValidator和RequiredFieldValidator?,javascript,asp.net,client-side-validation,Javascript,Asp.net,Client Side Validation,我有3个文本框当前密码、新密码和确认密码,每个文本框有3个RequiredFieldValidator,新密码和确认密码有一个comparevalidator 我还使用CustomValidator,因为我想检查当前密码是否正确。所以我创建了一个javascript函数来检查当前密码 步骤: 1.如果当前密码不正确,则显示“当前密码不正确”的警报消息,该消息正常 2.但如果两者不匹配,则会向前移动并显示警告消息“新密码和确认密码字段必须相同” 我想要的是,它不应该进一步移动它在步骤1中显示消息

我有3个文本框当前密码、新密码和确认密码,每个文本框有3个RequiredFieldValidator,新密码和确认密码有一个comparevalidator

我还使用CustomValidator,因为我想检查当前密码是否正确。所以我创建了一个javascript函数来检查当前密码

步骤:

1.如果当前密码不正确,则显示“当前密码不正确”的警报消息,该消息正常

2.但如果两者不匹配,则会向前移动并显示警告消息“新密码和确认密码字段必须相同”

我想要的是,它不应该进一步移动它在步骤1中显示消息

有人知道怎么做吗

谢谢

PS:

错误


禁用CompareValidator,禁用其客户端脚本,并根据密码验证结果在当前密码CustomValidator的服务器验证方法中启用:

标记:

Current password: <asp:TextBox runat="server" ID="CurrentPassword" TextMode="Password" />
<asp:CustomValidator runat="server" ID="CurrentPasswordValidator" ValidateEmptyText="true"
ControlToValidate="CurrentPassword" OnServerValidate="CurrentPasswordValidator_ServerValidate"
ErrorMessage="current password is not correct" />
<br />
New Password: <asp:TextBox runat="server" ID="NewPassword1" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="NewPassword1" >*</asp:RequiredFieldValidator>
<br />
Confirm Password: <asp:TextBox runat="server" ID="NewPassword2" TextMode="Password" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="NewPassword2" >*</asp:RequiredFieldValidator>
<asp:CompareValidator runat="server" ID="CompareNewPasswordsValidator"
     ControlToValidate="NewPassword2" ControlToCompare="NewPassword1" EnableClientScript="false"
     ErrorMessage="New Password and Confirm Password Fields must be identical" Enabled="false" />
<br /> 
<asp:Button ID="ResetPasswordButton" runat="server" Text="Reset Password" OnClick="ResetPasswordButton_Click" />

您可以在脚本上禁用验证程序,如下所示:

 var CmpValidator = document.getElementById('<%=CompareValidator1.ClientID%>');
 ValidatorEnable(CmpValidator, false); 
var CmpValidator=document.getElementById(“”);
ValidatorEnable(CmpValidator,false);
稍后,在客户端单击“提交”按钮时,您可以启用它,如下所示:

 var CmpValidator = document.getElementById('<%=CompareValidator1.ClientID%>');
 ValidatorEnable(CmpValidator, true); 
var CmpValidator=document.getElementById(“”);
ValidatorEnable(CmpValidator,true);

我按照您提供的解决方案进行了尝试,但它给了我错误。您可以在我的问题中看到错误。请查看更新的问题
 var CmpValidator = document.getElementById('<%=CompareValidator1.ClientID%>');
 ValidatorEnable(CmpValidator, true);