我在 asp.net 中创建了一个简单的注册表单。这是我的问题:如果我的确认密码字段为空,它仍会提交表单。我正在使用 compareToValidate 是否还需要使用 requiredvalidator。我是 asp.net 的新手,但如果假设密码为 123 并且确认密码为空,则 comparevalidator 不应该生成错误。
<fieldset>
<legend>Enter your data</legend>
<table>
<tr>
<td align="right">User Name :</td>
<td> </td>
<td align="left">
<asp:TextBox ID="tbUsername" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvUserName" runat="server"
ControlToValidate="tbUsername"
CssClass="ValidationError"
ErrorMessage="« (Required)"
ToolTip="User Name is a REQUIRED field"
></asp:RequiredFieldValidator>
</td>
</tr>`enter code here`
<tr >
<td align="right">Password : </td>
<td> </td>
<td align="left">
<asp:TextBox ID="tbPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="« (Required)"
ControlToValidate="tbPassword"
CssClass="ValidationError"
ToolTip="Password is a REQUIRED field"
></asp:RequiredFieldValidator>
</td>
</tr>
<tr >
<td align="right">Confirm Password : </td>
<td> </td>
<td align="left">
<asp:TextBox ID="ConfirmPass" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="ConfirmPass"
CssClass="ValidationError"
ControlToCompare="tbPassword"
ErrorMessage="No Match"
ToolTip="Password must be the same" />
</td>
</tr>