我在 Web 表单上有两个文本框控件,txtPassword 和 txtPassword2。
使用 CompareValidator 控件,两个字段都需要匹配。
txtPassword = ""
txtPassword2 = ""
No compare error
txtPassword throws it's required field error
txtPassword = "1"
txtPassword2 = ""
No compare error
txtPassword = ""
txtPassword2 = "1"
Compare error
txtPassword throws it's required field error
txtPassword = "1"
txtPassword2 = "2"
Compare error
知道为什么它缺少 txtPassword2 的空白值吗?
这是代码:
<asp:TextBox ID="txtPassword" Text="" TextMode="Password" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required!" ControlToValidate="txtPassword"></asp:RequiredFieldValidator>
<asp:TextBox ID="txtPassword2" Text="" TextMode="Password" runat="server"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Passwords do not match!" ControlToValidate="txtPassword2" ControlToCompare="txtPassword"></asp:CompareValidator>