Banner Ad

Thursday, January 17, 2013

Validators In ASP.Net - Part 3 : Compare Validator

By Francis   Posted at   12:03 PM   Validators in ASP.Net No comments
Compare Validator
 
In this article, I’m going to explain about the compare validator. The compare validator is used to compare the values entered in a one input control with another constant value or value entered against in another control.



 Copy and paste the following code into the .aspx page:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="CompareValidator.aspx.vb"
    Inherits="CompareValidator" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td>
                    Age From:
                </td>
                <td style="font-family: Verdana;">
                    <asp:TextBox ID="txtAgeFrom" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Age To:
                </td>
                <td>
                    <asp:TextBox ID="txtAgeTo" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Compare with Constant : Age From must be greater than 0"
                        Operator="GreaterThan" ControlToValidate="txtAgeFrom" ValueToCompare="0" Type="Integer"></asp:CompareValidator>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:CompareValidator ID="CompareValidator2" runat="server" ErrorMessage="Compare with Another Control Value : Age To should be greater than Age From"
                        Operator=" GreaterThan" ControlToValidate="txtAgeTo" ControlToCompare="txtAgeFrom"
                        Type="Integer"></asp:CompareValidator>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

Output:


Compare Validator

 Happy Programming!!!

About Francis

Francis, an Associate at Cognizant. Having 7+ Years of experience in Microsoft web technologies.

0 comments :

Please give your valuable comments to improve the contents

Connect with Us