为了比较两个控件的值,此时我们需要使用CompareValidator 控件。
在下面的这个例子中,我们将讲解CompareValidator 控件的用法。
先看文件validata4.aspx:
<!--源文件:form\web页面简介\validate4.aspx-->
<%@ Page clienttarget=downlevel %>
<html>
<title>CompareValidator控件示例</title>
<head>
<script language="VB" runat="server">
Sub Button1_OnSubmit(sender As Object, e As EventArgs)
If Page.IsValid Then
lblOutput.Text = "比较正确!"
Else
lblOutput.Text = "比较不正确!"
End If
End Sub
Sub lstOperator_SelectedIndexChanged(sender As Object, e As EventArgs)
comp1.Operator = lstOperator.SelectedIndex
comp1.Validate
End Sub
</script>
</head>
<body>
<center>
<h3><font face="Verdana">CompareValidator控件示例</font></h3>
<form runat=server>
<table bgcolor="#eeeeee" cellpadding=10>
<tr valign="top">
<td>
<h5><font face="Verdana">字符串 1:</font></h5>
<asp:TextBox Selected id="txtComp" runat="server"></asp:TextBox>
</td>
<td>
<h5><font face="Verdana">比较运算符:</font></h5>
<asp:ListBox id="lstOperator" OnSelectedIndexChanged="lstOperator_SelectedIndexChanged" runat="server">
<asp:ListItem Selected Value="Equal" >=</asp:ListItem>
<asp:ListItem Value="NotEqual" ><></asp:ListItem>
<asp:ListItem Value="GreaterThan" >></asp:ListItem>
<asp:ListItem Value="GreaterThanEqual" >>=</asp:ListItem>
<asp:ListItem Value="LessThan" ><</asp:ListItem>
<asp:ListItem Value="LessThanEqual" >=<</asp:L