Partager via


Introduction to the RequiredFieldValidator Control 

Use the RequiredFieldValidator control to validate that the user entered a data value into a SelectionList or TextBox control. With a SelectionList control, the user must select an item in the list. With a TextBox control, the user must enter a value.

ASP.NET Required Field Validator

Set the RequiredFieldValidator control's ControlToValidate property to the ID of the SelectionList or TextBox control to validate. If the data value is not present, the RequiredFieldValidator control displays the value of its ErrorMessage property.

When you add a RequiredFieldValidator control to a container control or template:

  • The ErrorMessage property is set to "RequiredFieldValidator".

  • The StyleReference property is set to error, which is the name of a predefined style in the default StyleSheet object.

For detailed information about properties of this control, see the Properties section of the RequiredFieldValidator topic.

See Also

Tasks

How to: Add and Configure a RequiredFieldValidator Control
How to: Add and Configure a CustomValidator Control
How to: Add and Configure a RangeValidator Control
How to: Add and Configure a RegularExpressionValidator Control
How to: Add and Configure a RequiredFieldValidator Control
How to: Add and Configure a ValidationSummary Control

Concepts

Introduction to the Validation Controls