Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP:NET Confirm Password field

Im creating a simple registration form in asp.net. Here's my problem: If my confirm passwordfield is empty it still submits the form. I'm using compareToValidate do I also need to use a requiredvalidator. I'm new to asp.net but shouldnt the comparevalidator generate an error if lets say password is 123 and the confirmpassword is empty.

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

like image 576
Dynamiite Avatar asked May 30 '13 13:05

Dynamiite


People also ask

How use compare validator for password in asp net?

Step 1 – Open Visual Studio –> Create a new empty Web application. Step 2 – Create a new web page and design web form with three textbox control along with button control. Step 3 – Drag and drop CompareValidator control from Toolbox.

What is the difference between password and confirm password?

Whenever a user creates a password, there is always one more field of confirm password. It checks that the password entered by the user is same as this confirm password fields. To create a valid password, both the password and confirm password fields value must be matched.

What is my MVC password and confirm password?

Refer below code. [Required(ErrorMessage = "Password is required." )] [Required(ErrorMessage = "Confirmation Password is required." )] [Compare( "Password" , ErrorMessage = "Password and Confirmation Password must match." )]

What is password confirm?

The confirm password catches typos by prompting users to type their password twice. While the confirm password field seems sensible, including it can lower your conversion rate.


1 Answers

You must provide a required validator as well! Compare validator will only compare the value with the target control and alert the user.

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

Hopes this help you!

like image 164
Fals Avatar answered Sep 20 '22 23:09

Fals