RangeValidator控件主要界定输入的值的范围。因为有时我们要求输入的值是要有一定范围的,所以我们要使用RangeValidator来判断。
在下面的这个例子中,我们将来介绍RangeValidator控件。
请看validata5.aspx的程序内容:
<!--源文件:form\web页面简介\validate5.aspx-->
<%@ Page clienttarget=downlevel %>
<html>
<center>
<title>RangeValidator控件演示</title>
<head>
<script language="VB" runat="server">
Sub Button1_Click(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)
rangeVal.Type = lstType.SelectedIndex
rangeVal.Validate
End Sub
</script>
</head>
<body>
<h3><font face="Verdana">RangeValidator控件演示</font></h3>
<p>
<form runat="server">
<table bgcolor="#eeeeee" cellpadding=10>
<tr valign="top">
<td>
<h5><font face="Verdana">输入要验证的值:</font></h5>
<asp:TextBox Selected id="txtComp" runat="server"/>
</td>
<td>
<h5><font face="Verdana">数据类型:</font></h5>
<asp:DropDownList id="lstType" OnSelectedIndexChanged="lstOperator_SelectedIndexChanged"runat=server>
<asp:ListItem Selected Value="String" >String</asp:ListItem>
<asp:ListItem Value="Integer" >Integer</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<h5><font face="Verdana">最小值:</font></h5>
<asp:TextBox id="txtMin" runat="server" />
</td>
<td>
<h5><font face="Verdana">最大值:</font></h5>
<asp:TextBox id="txtMax" runat="server" /><p>
<asp:Button Text="验证" ID="Button1" onclick="Button1_Click" runat="server" />
</td>
</tr>
<asp:RangeValidator id="rangeVal" Type="String" ControlToValidate="txtComp" MaximumControl="txtMax" MinimumControl="txtMin" runat="server"/>
<br>
<asp:Label id="lblOutput" Font-Name="verdana" Font-Size="10pt" runat="server" />
</form>
</body>
</center>
</html>
当我们在三个文本框中分别输入要验证的值,最大值,和最小值,然后按下验证按钮,页面上将显示判
关键词:验证控件介绍--RangeValidator