RequiredFieldValidator control
ASP.NET RequiredFieldValidator Control
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
Properties | Description |
---|---|
BackColor | RequiredFieldValidator The background color of the control. |
ControlToValidate | The id of the control to be validated. |
Display | Verify the display behavior of the control. Legal values are:
|
EnableClientScript | Boolean value, specifies whether to enable client verification. |
Enabled | Boolean value, specifies whether to enable the validation control. |
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. |
InitialValue | Set the initial value (start value) of the input control. The default is "". |
IsValid | Boolean value indicating whether the control specified by ControlToValidate passed validation. |
runat | Specifies that the control is a server control. Must be set to "server". |
Text | The 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.
Validation Server Control