ASP.NET Syntax ASP.NET Syntax for Validation Controls
You can use this control to ensure that the user does not skip an entry.
<asp:RequiredFieldValidator id="accessID"
ControlToValidate = "ID of input control to validate"
InitialValue = ""
ErrorMessage = "message to display in ValidationSummary control"
Text = "message to display in control"
ForeColor = "color value"
BackColor = "color value"
runat="server" />
For information on the individual members of this class, see RequiredFieldValidator in the class library.
Use the RequiredFieldValidator control to make an input control a mandatory field. The input control fails validation if the value it contains does not change from its initial value when validation is performed. This prevents the user from leaving the associated input control unchanged. By default, the initial value is an empty string ( "" ), which indicates that a value must be entered in the input control for it to pass validation.
NOTE: Extra spaces at the beginning and end of the input value are removed before validation is performed. This prevents a space being entered in the input control from passing validation.
In certain cases, you may want to have an initial value that is not an empty string. This is useful when you have a default value for an input control and want the user to select a different value.
For example, you can have a ListBox control with an entry selected by default, that contains instructions to the user to select an item from the list. The user must select an item from the control, but you do not want the user to select the item containing the instructions. You can prevent the user from selecting this item by specifying its value as the initial value. If the user selects this item, the RequiredFieldValidator displays its error message. To specify the starting value of the associated input control, set the InitialValue property.
NOTE: The InitialValue property does not set the default value for the input control. The InitialValue property does not even need to match the default value of the input control. It simply indicates the value that you do not want the user to enter in the input control. The input control fails validation if it contains this value when validation is performed.
Multiple validators can be associated with the same input control. For example, a RequiredFieldValidator can be used to ensure input to a control, while at the same time, a RangeValidator can be used to ensure that the input is within a specified data range.
The following example demonstrates how to use the RequiredFieldValidator control to force the user to make an entry in a textbox input control.
Show me
RequiredFieldValidator Class Validating Required Entries Data Entry Validation ( Client-Side )