ASP.NET CustomValidatorControl
Validation Server Control
Definition and Usage
The CustomValidator control allows you to write methods that handle validation of input values.
Properties
| Properties | Description |
|---|---|
| BackColor | The background color of the CustomValidator control. |
| ClientValidationFunction | Specifies the name of the client-side 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 placed inside the form: Sub FunctionName (source, arguments) When using JScript, the function must be placed inside the form: Function FunctionName (source, arguments) |
| ControlToValidate | The id of the control to validate. |
| Display | The display behavior of the validation control. Valid values are:
|
| EnableClientScript | A Boolean value that specifies whether client-side validation is enabled. |
| Enabled | A Boolean value that specifies whether the validation control is enabled. |
| ErrorMessage | The 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. |
| ForeColor | The foreground color of the control. |
| id | The unique id of the control. |
| IsValid | A Boolean value that indicates whether the control specified by ControlToValidate passes validation. |
| OnServerValidate | Specifies 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". |
| Text | The message displayed when validation fails. |
Example
CustomValidator
In this example, we declare two Label controls, a TextBox control, a Button control, and a CustomValidator control in the .aspx file. The user() function can detect 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.
Validation Server Control Other Extensions