asp.net – ASP:NET确认密码字段

前端之家收集整理的这篇文章主要介绍了asp.net – ASP:NET确认密码字段前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在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>

希望这对你有所帮助!

原文链接:https://www.f2er.com/aspnet/248036.html

猜你在找的asp.Net相关文章