Home » ASP.Net Web Form Required Field Validator

ASP.Net Web Form Required Field Validator

by Online Tutorials Library

ASP.NET RequiredFieldValidator Control

This validator is used to make an input control required. It will throw an error if user leaves input control empty.

It is used to mandate form control required and restrict the user to provide data.

Note: It removes extra spaces from the beginning and end of the input value before validation is performed.

The ControlToValidateproperty should be set with the ID of control to validate.

RequiredFieldValidator Properties

Property Description
AccessKey It is used to set keyboard shortcut for the control.
BackColor It is used to set background color of the control.
BorderColor It is used to set border color of the control.
Font It is used to set font for the control text.
ForeColor It is used to set color of the control text.
Text It is used to set text to be shown for the control.
ToolTip It displays the text when mouse is over the control.
Visible To set visibility of control on the form.
Height It is used to set height of the control.
Width It is used to set width of the control.
ErrorMessage It is used to set error message that display when validation fails.
ControlToValidate It takes ID of control to validate.

Example

Here, in the following example, we are explaining RequiredFieldValidator control and creating to mandatory TextBox controls.

// RequiredFieldValidator.aspx

Output:

It produces the following output when view in the browser.

ASP Required 1

It throws error messages when user login with empty controls.

ASP Required 2

You may also like