Sponsored Ad

Tuesday, June 15, 2010

How to Compaire Two Integer Values in ASP.NET | CompareValidator

Compairing two integer values in asp.net 2.0 and above versions are very easy now. You can just use the CompareValidator control and given the first textbox name and second textbox name as given in below example.

012 and 12 integer values are same, so it is not giving any error.

While 12 and 120 are different integer values, so there is error message.

 

How to Compaire Two Integer Values in ASP.NET | CompareValidator

How to Compaire Two Integer Values in ASP.NET | CompareValidator1

 

How to Compaire Two Integer Values in ASP.NET | CompareValidator Example:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<body>
    <form id="Form1" runat="server">
        <h4>
            Compare two Integer values</h4>
       Integer Value 1:
        <asp:TextBox ID="txtNumber1" runat="server" />
        <br />
        <br />
        Integer Value 2:
        <asp:TextBox ID="txtNumber2" runat="server" />
        <br />
        <br />
        <br />
        <asp:Button ID="Button1" Text="Validate" runat="server" />
        <br />
        <br />   
        <asp:CompareValidator ID="compair_values"  ControlToValidate="txtNumber1" ControlToCompare="txtNumber2"
            ForeColor="red" Type="integer"  Text="Please enter same integer values in both textboxes."
            runat="server" />
    </form>
</body>
</html>

No comments:

Post a Comment

Sponsored Ad

Development Updates