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

CustomValidator control


ASP.NET CustomValidator Control


up.gif Validation server control

Definition and usage

CustomValidator control allows You write methods that handle input value validation.


Properties

##ControlToValidateTo The id of the control being verified. DisplayVerify the display behavior of the control. Legal values ​​are: EnableClientScriptBoolean value, specifies whether to enable client-side verification. EnabledBoolean value, specifies whether to enable the validation control. ErrorMessageThe text displayed in the ValidationSummary control when validation fails. ForeColorThe foreground color of the control. idThe unique id of the control. IsValidBoolean value indicating whether the control specified by ControlToValidate passed validation. OnServerValidateSpecifies the name of the server-side validation script function to be executed. runat Specifies that the control is a server control. Must be set to "server". TextThe message displayed when verification fails.

Example

CustomValidator
In this example, we declared two Label controls, a TextBox control, a Button control, and a CustomValidator control in the .aspx file . The user() function detects the length of the input value. If the length is less than 8 or greater than 16, the text "A username must be between 8 and 16 characters!" is displayed in the CustomValidator control.


up.gif Validation Server Control
PropertiesDescription
BackColorCustomValidator The background color of the control.
ClientValidationFunctionSpecifies the name of the client script function to be executed. Note: The script must be written in a language supported by the browser, such as VBScript or JScript

When using VBScript, the function must be located within the form:

Sub FunctionName (source, arguments)

When using JScript, the function must be located within the form:

Function FunctionName (source, arguments)

    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.
Note: If the Text property is not set, the text will also be displayed in the validation control.