Friday, December 14, 2012

ASP.NET Validation Controls: Compare Validator


In a user registration form submitting the password is a common application. In such a case we need to ensure that the user entered his/her expected  password. To ensure we can let user to enter the password two times and compare the password in the two text boxes. CompareValidator can be used in this scenario.

 <table>

            <tr>
                <td>Password: </td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" TextMode="Password"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Retype Password:</td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
&nbsp;<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox1"
                        ControlToValidate="TextBox2" ForeColor="#CC0000">Password mismatch</asp:CompareValidator>
                </td>
            </tr>
            <tr>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td><asp:Button ID="Button3" runat="server" Text="Submit" /> </td>
            </tr>
        </table>

No comments:
Write comments
Recommended Posts × +