我正在使用 UpdatePanel 并希望将 CompareValidator 放在两个文本框上,以验证用户输入的密码和确认是否相同。
这是开箱即用的(我有 VS2008 并且正在使用 .NET 3.5),但有一个小问题:
一旦用户点击第一个文本框,验证就会触发,然后他们才有机会输入第二个文本框。这不会导致任何真正的问题,以编程方式(所有发生的只是错误消息显示,当他们输入确认时它消失了)但我们的测试人员说这是一个问题。在他们点击“保存”之前验证不会触发,它才会通过 UA 测试。
如何让 CompareValidator 在他们在两个框中都输入文本之前不触发?
编辑:
这是标记的示例。
<div>
<div><asp:Label runat="server" ID="lblPassword" Text="Password"/></div>
<div><asp:TextBox runat="server" TextMode="password" ID="txtPassword" size="25" /></div>
</div>
<div>
<div><asp:Label runat="server" ID="lblConfirmPassword" Text="Confirm Password"/></div>
<div><asp:TextBox runat="server" TextMode="password" ID="txtConfirmPassword" size="25" /></div>
</div>
<asp:CompareValidator ID="CompareValidator1" ValidationGroup="PublishPassValidation" ControlToValidate="txtPassword" ControlToCompare="txtConfirmPassword" runat="server" ErrorMessage="Passwords do not match"></asp:CompareValidator>
以上内容位于页面上 UpdatePanel 的 ContentTemplate 中包含的控件中。
(为简洁起见,删除了 CSS 类和样式)