-->
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txtAge" Operator="DataTypeCheck" Type="Integer" ErrorMessage="|| (Invalid Age || " Display="None" ValidationGroup="Validation" SetFocusOnError="true" />
<%@ Page Language="C#" AutoEventWireup="true" %> <!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 id="Head1" runat="server"> <title></title> <style> .column { float: left; width: 30%; margin-left: 10px; background-color: white; border: solid 1px black; padding: 10px; width: 70%; } fieldset { background-color: #a9a9a9; border: solid 2px #d81a72; color:Black; width:93%; } </style> </head> <body style="width: 70%;"> <form id="form1" runat="server" > <div class="column"> <fieldset> <legend>CompareValidator Demo</legend> <asp:Label ID="Label1" Text="Start Date:" runat="server" /> <asp:TextBox ID="txtStartDt" runat="server" ValidationGroup="CompareValidator" /> <br /> <br /> <asp:Label ID="Label2" Text="End Date:" runat="server" /> <asp:TextBox ID="txtEndDt" runat="server" ValidationGroup="CompareValidator" /> <asp:CompareValidator ID="cvDateCompare" ErrorMessage="(End date must be greater than start date)" ValidationGroup="CompareValidator" ControlToValidate="txtStartDt" ControlToCompare="txtEndDt" EnableClientScript="true" Type="Date" Operator="LessThan" SetFocusOnError="true" runat="server" /> <br /> <asp:Button ID="btncvSubmit" Text="Submit" runat="server" ValidationGroup="CompareValidator" /> <asp:Button ID="btncvReset" Text="Reset" runat="server" ValidationGroup="CompareValidator" CausesValidation="false" /> </fieldset> </div> </form> </body> </html>
Thanks for reading Asp.Net CompareValidator Control