ASP.NET RequiredFieldValidator Control
ASP.NET Tutorial
WP Tutorial
- WebPages Introduction
- WebPages Razor
- WebPages Layout
- WebPages Folders
- WebPages Global
- WebPages Forms
- WebPages Objects
- WebPages Files
- WebPages Helpers
- WebPages WebGrid
- WebPages Charts
- WebPages Email
- WebPages PHP
- WebPages Publish
- WebPages Examples
WP Reference Manual
ASP.NET Razor
- Razor Introduction
- Razor Syntax
- Razor C# Variables
- Razor C# Loops
- Razor C# Logic
- Razor VB Variables
- Razor VB Loops
- Razor VB Logic
ASP.NET MVC
- MVC Introduction
- MVC Application
- MVC Folders
- MVC Layout
- MVC Controllers
- MVC Views
- MVC Database
- MVC Models
- MVC Security
- MVC HTML Helpers
- MVC Publish
- MVC Reference
WF Tutorial
- WebForms Introduction
- WebForms Pages
- WebForms Controls
- WebForms Events
- WebForms Forms
- WebForms ViewState
- WebForms TextBox
- WebForms Button
- WebForms Data Binding
- WebForms ArrayList
- WebForms Hashtable
- WebForms SortedList
- WebForms XML Files
- WebForms Repeater
- WebForms DataList
- WebForms Database Connection
- WebForms Master Pages
- WebForms Navigation
- WebForms Examples
WF Reference Manual
ASP.NET RequiredFieldValidator Control
Definition and Usage
The RequiredFieldValidator control is used to make an input control a required (mandatory) field.
The validation fails if the initial value of the input is not changed. By default, the initial value is an empty string ("").
Note: Whitespace at the beginning and end of the input value is 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 the user to enter in the input control.
Properties
| Property | Description |
|---|---|
| BackColor | The background color of the RequiredFieldValidator control. |
| ControlToValidate | The id of the control to validate. |
| Display | The display behavior of the validation control. Valid values are:
|
| EnableClientScript | Boolean value that specifies whether to enable client-side validation. |
| Enabled | Boolean value that 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 is also displayed in the validation control. |
| ForeColor | The foreground color of the control. |
| id | A unique id for the control. |
| InitialValue | The initial (starting) value for the input control. The default is "". |
| IsValid | Boolean value indicating whether the control specified by ControlToValidate has passed validation. |
| runat | Specifies that the control is a server control. Must be set to "server". |
| Text | The message displayed when validation fails. |
Example
In this example, we declare two TextBox controls, one Button control, and one RequiredFieldValidator control in an .aspx file. It demonstrates how to use the RequiredFieldValidator control to make the "txt_name" text box a required (mandatory) field.
YouTip