<%@ Page Language="C#"%> <!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>Using CompareValidator Control</title> </head> <body> <form id="form1" runat="server"> <div> Age:<br /> <asp:TextBox ID="txtAge" runat="server"></asp:TextBox> <asp:CompareValidator ID="compAge" runat="server" ControlToValidate="txtAge" ValueToCompare="18" Operator="LessThanEqual" SetFocusOnError="true" Text="You are too old to view this site" /> Sales Date:<br /> <asp:TextBox ID="txtDate" runat="server"></asp:TextBox> <asp:CompareValidator ID="compDate" runat="server" ControlToValidate="txtDate" Operator="DataTypeCheck" Type="Date" Text="Enter a valid date" /> Quantity:<br /> <asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox> <asp:CompareValidator ID="compQuantity" runat="server" ControlToValidate="txtQuantity" Operator="DataTypeCheck" Type="Integer" Text="Enter a valid whole number" /> Enter Password:<br /> <asp:TextBox ID="txtPass1" runat="server" TextMode="password"></asp:TextBox> Reenter Password:<br /> <asp:TextBox ID="txtPass2" runat="server" TextMode="password"></asp:TextBox> <asp:CompareValidator ID="compPass" runat="server" ControlToValidate="txtPass2" Operator="Equal" ControlToCompare="txtPass1" Text="Passwords must match" /> <asp:Button ID="btnSubmit" Text="Click this to test validation" runat="server" /> </div> </form> </body> </html>