ASP.NET Tutoria...login
ASP.NET Tutorial
author:php.cn  update time:2022-04-11 14:18:18

RangeValidator control


ASP.NET RangeValidator Control


up.gif Validation server control

Definition and usage

RangeValidator control Used to detect whether the value entered by the user is between two values. Different types of values ​​can be compared, such as numbers, dates, and characters.

Note: If the input control is empty, validation will not fail. Use the RequiredFieldValidator control to make a field required (required).

Note: If the input value cannot be converted to the specified data type, validation will not fail. Use the CompareValidator control and set its Operator property to ValidationCompareOperator.DataTypeCheck to verify the data type of the input value.


Properties

PropertiesDescription
BackColorRangeValidator The background color of the control.
ControlToValidateThe id of the control to be validated.
DisplayVerify the display behavior of the control. Legal values ​​are:
  • None - the control is not displayed. Used only to display error messages in the ValidationSummary control.
  • Static - If validation fails, the control displays an error message. Even if the input passes validation, space is reserved on the page to display the message, that is, the space used to display the message is allocated in advance.
  • Dynamic - If validation fails, the control displays an error message. If the input passes validation, no space is reserved on the page to display the message, that is, the space used to display the message is added dynamically.
EnableClientScriptBoolean value, specifies whether to enable client verification.
EnabledBoolean value, specifies whether to enable the validation control.
ErrorMessageThe text displayed in the ValidationSummary control when validation fails. Note: If the Text property is not set, the text will also be displayed in the validation control.
ForeColorThe foreground color of the control.
idThe unique id of the control.
IsValidBoolean value indicating whether the control specified by ControlToValidate passed validation.
MaximumValueSpecifies the maximum value of the input control.
MinimumValueSpecifies the minimum value of the input control.
runat Specifies that the control is a server control. Must be set to "server".
TypeSpecifies the data type of the value to be detected. Types are:
  • Currency
  • Date
  • Double
  • Integer
  • String
TextThe message displayed when verification fails.


Example

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

RangeValidator 2
In this example, we declare a TextBox control, a Button control, a Label control, and a RangeValidator control in the .aspx file. The submit() function can detect whether the page is valid. If valid, returns "The page is valid!" in the Label control. If it is invalid, "The page is not valid!" is returned in the Label control. If validation fails, "The value must be from 1 to 100!" is displayed in the RangeValidator control.


up.gif Validation Server Control

php.cn