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

RequiredFieldValidator control


ASP.NET RequiredFieldValidator Control


up.gif Validation server control

Definition and usage

RequiredFieldValidator control Used to make the input control a required (required) field.

With this control, if the initial value of the input value has not changed, the verification fails. By default, the initial value is the empty string ("").

Note: Leading and trailing spaces in the input value will be removed before validation.

Note: The InitialValue property does not set a default value for the input control. It indicates a value that you do not want users to enter in the input control.


Properties

PropertiesDescription
BackColorRequiredFieldValidator 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.
InitialValue Set the initial value (start value) of the input control. The default is "".
IsValidBoolean value indicating whether the control specified by ControlToValidate passed validation.
runat Specifies that the control is a server control. Must be set to "server".
TextThe message displayed when verification fails.


Example

RequiredFieldValidator
In this example, we declare two TextBox controls, a Button control, and a RequiredFieldValidator control in the .aspx file. It demonstrates how to use the RequiredFieldValidator control to make the "txt_name" text box a required (required) field.


up.gif Validation Server Control

php.cn