Pages

Saturday, April 26, 2008

RequiredFieldValidator Control

The RequiredFieldValidator control is used to ensure that fields that must be populated with data are, indeed, populated with data. This control can be used with virtually any data entry controls, such as TextBox, DropDownList, and CheckBox. The RequiredFieldValidator control works by comparing the selected value of the control specified in the ControlToValidate property against an initial value that you specify. If you do not specify an initial value, an empty string is assumed.

This initial value against which comparisons are made is established using the InitialValue property. The default value is an empty string. However, you can set it to any value you like. Suppose, for example, you want to provide some assistance to users specifying dates by pre-filling the date field with MM/DD/YYYY. In this situation, you can set the InitialValue property of the associated RequiredFieldValidator control. This means that the user is still required to specify a value and cannot rely on the initial default value that you provide for guidance.

No comments: