首页 > 开发 > 综合 > 正文

验证控件介绍--RangeValidator

2024-07-21 02:22:01
字体:
来源:转载
供稿:网友
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>
     </table>
     <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>
当我们在三个文本框中分别输入要验证的值,最大值,和最小值,然后按下验证按钮,页面上将显示判断的结果。
  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。
  • 发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表