欢迎光临
我们一直在努力

使用RangeValidator-.NET教程,评论及其它

建站超值云服务器,限时71元/月

rangevalidator 服务器控件测试输入值是否位于给定的范围内。rangevalidator 使用三个键属性执行验证。controltovalidate 包含要验证的值。minimumvalue 和 maximumvalue 定义有效范围的最小值和最大值。本例显示如何使用 rangevalidator 控件。
<%@ page clienttarget=downlevel %>

<html>
<head>
    <script language=”c#” runat=”server”>
        void button1_click(object sender, eventargs e) {
           rangevalinteger.validate();
           if (rangevalinteger.isvalid) {
               lbloutput1.text = “结果:有效!”;
           } else {
               lbloutput1.text = “结果:无效!”;
           }

           rangevaldate.validate();
           if (rangevaldate.isvalid) {
               lbloutput2.text = “结果:有效!”;
           } else {
               lbloutput2.text = “结果:无效!”;
           }

           rangevalstring.validate();
           if (rangevalstring.isvalid) {
               lbloutput3.text = “结果:有效!”;
           } else {
               lbloutput3.text = “结果:无效!”;
           }

           if (page.isvalid) {
              lbloutput.text = “结果:页有效!”;
           } else {
              lbloutput.text = “结果:页无效!”;
           }
        }
   </script>
</head>
<body>
    <h3><font face=”宋体”>rangevalidator 示例</font></h3>
    <p>
    <form runat=”server”>
      <table bgcolor=”#eeeeee” cellpadding=10>
      <tr valign=”top”>
        <td>
            <h5><font face=”宋体”>要检查的值:</font></h5>
            <asp:textbox id=”txtcomp1″ runat=”server”/>
        </td>
        <td>
            <h5><font face=”宋体”>数据类型:整型最小值 (1),最大值 (10)</font></h5>
        </td>
        <td>
             <asp:label id=”lbloutput1″ font-name=”宋体” font-size=”10.5pt” runat=”server” />
        </td>
      </tr>
      <tr valign=”top”>
        <td>
            <h5><font face=”宋体”>要检查的值:</font></h5>
            <asp:textbox id=”txtcomp2″ runat=”server”/>
        </td>
        <td>
            <h5><font face=”宋体”>数据类型:日期最小值 (2000/1/1),最大值 (2001/1/1)</font></h5>
        </td>
        <td>
             <asp:label id=”lbloutput2″ font-name=”宋体” font-size=”10.5pt” runat=”server” />
        </td>
      </tr>
      <tr valign=”top”>
        <td>
            <h5><font face=”宋体”>要检查的值:</font></h5>
            <asp:textbox id=”txtcomp3″ runat=”server”/>
        </td>
        <td>
            <h5><font face=”宋体”>数据类型:字符串最小值 (aardvark),最大值 (zebra)</font></h5>
        </td>
        <td>
             <asp:label id=”lbloutput3″ font-name=”宋体” font-size=”10.5pt” runat=”server” />
        </td>
      </tr>
     </table>
     <asp:button text=”验证” id=”button1″ onclick=”button1_click” runat=”server” />
     <asp:rangevalidator
        id=”rangevalinteger”
        type=”integer”
        controltovalidate=”txtcomp1″
        maximumvalue=”10″
        minimumvalue=”1″
        runat=”server”/>
     <asp:rangevalidator
        id=”rangevaldate”
        type=”date”
        controltovalidate=”txtcomp2″
        maximumvalue=”2001/1/1″
        minimumvalue=”2000/1/1″
        runat=”server”/>
     <asp:rangevalidator
        id=”rangevalstring”
        type=”string”
        controltovalidate=”txtcomp3″
        maximumvalue=”zebra”
        minimumvalue=”aardvark”
        runat=”server”/>
     <br>
     <asp:label id=”lbloutput” font-name=”宋体” font-size=”10.5pt” runat=”server” />
    </form>
</body>
</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 使用RangeValidator-.NET教程,评论及其它
分享到: 更多 (0)