<%@ Page clienttarget=downlevel %>
<html>
<head>
<title>CompareValidator Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void ValidateBtnClick ( object src, EventArgs e ) {
if ( Page.IsValid ) {
lblmsg.Text = "Comparison is valid!";
}
else {
lblmsg.Text = "Comparison is not valid!";
}
}
void lstOperator_SelectedIndexChanged ( object src, EventArgs e ) {
comp1.Operator= ( ValidationCompareOperator ) lstOperator.SelectedIndex;
comp1.Validate ( );
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>CompareValidator Example</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<p>Type a value in each textbox, select a comparison operator, then click "Validate" to test.</p>
<table bgcolor="#eeeeee" cellpadding=10>
<tr valign="top">
<td><h5>String 1:</h5>
<asp:textbox selected id="txtComp" runat="server"></asp:textbox>
<br>
<asp:requiredfieldvalidator
controltovalidate="txtComp"
errormessage="Field cannot be blank" runat="server" />
</td>
<td><h5>Comparison Operator:</h5>
<asp:listbox id="lstOperator" onSelectedIndexChanged="lstOperator_SelectedIndexChanged" runat="server">
<asp:listitem selected value="Equal">Equal</asp:listitem>
<asp:listitem value="NotEqual">NotEqual</asp:listitem>
<asp:listitem value="GreaterThan">GreaterThan</asp:listitem>
<asp:listitem value="GreaterThanEqual">GreaterThanEqual</asp:listitem>
<asp:listitem value="LessThan">LessThan</asp:listitem>
<asp:listitem value="LessThanEqual">LessThanEqual</asp:listitem>
</asp:listbox></td>
<td>
<h5>String 2:</h5>
<asp:textbox id="txtCompTo" runat="server"></asp:textbox>
<br>
<asp:requiredfieldvalidator
controltovalidate="txtCompTo"
errormessage="Field cannot be blank" runat="server" />
</td></tr>
</table>
<br>
<asp:button runat="server"
text="Validate" onClick="ValidateBtnClick" />
<br>
<asp:comparevalidator id="comp1"
controltovalidate="txtComp"
controltocompare="txtCompTo"
type="String" runat="server" />
<br>
<asp:label id="lblmsg" runat="server" />
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>