日期:2012-08-24  浏览次数:20423 次

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>