日期:2008-12-12  浏览次数:20387 次

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