CustomValidator control
ASP.NET CustomValidator 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.

Properties | Description |
---|---|
BackColor | CustomValidator The background color of the control. |
ClientValidationFunction | Specifies 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) |
| |
Note: If the Text property is not set, the text will also be displayed in the validation control. | |