禁用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" />
代碼:
protected void CurrentPasswordValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
if (args.Value == "123")
{
args.IsValid = true;
CompareNewPasswordsValidator.Enabled = true;
}
else
{
args.IsValid = false;
CompareNewPasswordsValidator.Enabled = false;
}
}
protected void ResetPasswordButton_Click(object sender, EventArgs e)
{
if (IsValid)
{
}
}
我試着按照你給出的解決方案給我錯誤。你可以在我的問題中看到錯誤。看到更新的問題 – Sukhjeevan
它的'javascript'錯誤。請張貼相關腳本。 – NaveenBhat
是的,它的工作,謝謝兄弟 – Sukhjeevan