Latest web development tutorials

ASP.NET RangeValidator Controls

Validation Server Controls Validation Server Controls

Definition and Usage

RangeValidator control value for detecting user input is between two values. You can compare different types of values, such as numbers, dates, and characters.

Note: If theinput control is empty, validation will not fail. Please use the RequiredFieldValidator control to make the field required (mandatory).

Note: If the input value can not be converted to the specified data type, verification will not fail.Use CompareValidator control, its Operator property to ValidationCompareOperator.DataTypeCheck, so you can check the data type of the input value.


Attributes

属性 描述
BackColor RangeValidator 控件的背景颜色。
ControlToValidate 要验证的控件的 id。
Display 验证控件的显示行为。合法值有:
  • None - 控件不显示。仅用于 ValidationSummary 控件中显示错误消息。
  • Static - 如果验证失败,控件显示错误消息。即使输入通过验证,也在页面上预留显示消息的空间,即用于显示消息的空间是预先分配好的。
  • Dynamic - 如果验证失败,控件显示错误消息。如果输入通过验证,页面上不预留显示消息的空间,即用于显示消息的空间是动态添加的。
EnableClientScript 布尔值,规定是否启用客户端验证。
Enabled 布尔值,规定是否启用验证控件。
ErrorMessage 当验证失败时,在 ValidationSummary 控件中显示的文本。 注释:如果未设置 Text 属性,文本也会显示在验证控件中。
ForeColor 控件的前景颜色。
id 控件的唯一 id。
IsValid 布尔值,指示由 ControlToValidate 指定的控件是否通过验证。
MaximumValue 规定输入控件的最大值。
MinimumValue 规定输入控件的最小值。
runat 规定该控件是一个服务器控件。必须设置为 "server"。
Type 规定要检测的值的数据类型。类型有:
  • Currency
  • Date
  • Double
  • Integer
  • String
Text 当验证失败时显示的消息。


Examples

RangeValidator
In this example, we declare a TextBox control in an .aspx file, a Button control, and a RangeValidator control. If the validation fails, the control will be displayed in RangeValidator text "The date must be between 1/1/2002 and 31/5/2002!".

RangeValidator 2
In this example, we declare in an .aspx file a TextBox control, a Button control, a Label control, and a RangeValidator control. submit () function detects the page is valid. If so, then in the Label control returns "The page is valid!". If not, then in the Label control returns "The page is not valid!". If the validation fails, RangeValidator control display "The value must be from 1 to 100!".


Validation Server Controls Validation Server Controls