使用RangeValidator控件
检测表单字段的值是否在指定的最小值和最大值之间
五个属性:
ControlToValidate---被验证的表单字段的ID
Text --验证失败时显示的错误信息
MininumValue
MaxinumValue
Type-比较类型:String,Integer,Double,Date和Currency 默认为String
[code]
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Show RangeValidator</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblAge" Text="Age:" AssociatedControlID="txtAge" runat="server" />
<asp:TextBox ID="txtAge" runat="server" />
<asp:RangeValidator ID="reqAge" ControlToValidate="txtAge" Text="(Invalid Age)" MinimumValue="5"
MaximumValue="100" Type="Integer" runat="server" />
<br />
<br />
<asp:Button ID="btnSubmit" Text="Submit" runat="server" />
</div>
</form>
</body>
</html>
[/code]
检测表单字段的值是否在指定的最小值和最大值之间
五个属性:
ControlToValidate---被验证的表单字段的ID
Text --验证失败时显示的错误信息
MininumValue
MaxinumValue
Type-比较类型:String,Integer,Double,Date和Currency 默认为String
[code]
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Show RangeValidator</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblAge" Text="Age:" AssociatedControlID="txtAge" runat="server" />
<asp:TextBox ID="txtAge" runat="server" />
<asp:RangeValidator ID="reqAge" ControlToValidate="txtAge" Text="(Invalid Age)" MinimumValue="5"
MaximumValue="100" Type="Integer" runat="server" />
<br />
<br />
<asp:Button ID="btnSubmit" Text="Submit" runat="server" />
</div>
</form>
</body>
</html>
[/code]