ASP field: NET Confirm Password

I am creating a simple registration form in asp.net. Here is my problem: If my password confirmation field is empty, it submits a form anyway. I use compareToValidate, also I need to use the required validator. I am new to asp.net, but should not refer to comparevalidator if it allows me to say that the password is 123 and the confirmation password 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> 

+7
source share
3 answers

You must also provide the necessary validator! The comparison 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> 

Hope this helps you!

+20
source

IMHO, that is exactly what he should do. The CompareValidator control is used to compare the value of one input control with the value of another input control or fixed value.

If the input control is empty, the verification functions are not called, and the verification is successful. Use the RequiredFieldValidator element so that the user does not skip the input control.

Link: http://msdn.microsoft.com/en-us/library/db330ayw(v=vs.100).aspx

+1
source

A simple method Its really working <asp:CompareValidator runat="server" ID="Comp1" ControlToValidate="tbPassword" ControlToCompare="ConfirmPass" Text="Password mismatch" Font-Size="11px" ForeColor="Red" />

0
source

All Articles