gpt4 book ai didi

asp.net - ASP :NET Confirm Password field

转载 作者:行者123 更新时间:2023-12-02 08:58:12 25 4
gpt4 key购买 nike

我正在 asp.net 中创建一个简单的注册表单。这是我的问题:如果我的确认密码字段为空,它仍然会提交表单。我正在使用compareToValidate,我还需要使用requiredvalidator吗?我是 ASP.NET 的新手,但如果假设密码是 123 并且确认密码为空,comparevalidator 不应该生成错误。

        <fieldset>
<legend>Enter your data</legend>
<table>
<tr>
<td align="right">User Name :</td>
<td>&nbsp;</td>
<td align="left">
<asp:TextBox ID="tbUsername" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvUserName" runat="server"
ControlToValidate="tbUsername"
CssClass="ValidationError"
ErrorMessage="&laquo; (Required)"
ToolTip="User Name is a REQUIRED field"
></asp:RequiredFieldValidator>
</td>
</tr>`enter code here`
<tr >
<td align="right">Password&nbsp;:&nbsp;</td>
<td>&nbsp;</td>
<td align="left">
<asp:TextBox ID="tbPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="&laquo; (Required)"
ControlToValidate="tbPassword"
CssClass="ValidationError"

ToolTip="Password is a REQUIRED field"
></asp:RequiredFieldValidator>
</td>

</tr>
<tr >
<td align="right">Confirm Password&nbsp;:&nbsp;</td>
<td>&nbsp;</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>

最佳答案

您还必须提供所需的验证器!比较验证器只会将值与目标控件进行比较并提醒用户。

<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" />

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="&laquo; (Required)"
ControlToValidate="ConfirmPass"
CssClass="ValidationError"
ToolTip="Compare Password is a REQUIRED field">
</asp:RequiredFieldValidator>
</td>

希望这对您有帮助!

关于asp.net - ASP :NET Confirm Password field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16837118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com