Web フォームに txtPassword と txtPassword2 の 2 つのテキスト ボックス コントロールがあります。
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>