RequiredFieldValidator Control

I l @ ve RuBoard

RequiredFieldValidator Control

The simplest of the validation controls is the RequiredFieldValidator control. This control, which you saw in our first example, simply checks to ensure that a value has been entered for a particular form control. If the required field is missing, this control will display its text and set the page's IsValid property to false. The control's Text should prompt the user that she needs to fill in a value for the associated control.

The RequiredFieldValidator control inherits all the BaseValidator's properties described in Table 8.1, and also exposes its own property described in Table 8.3.

Table 8.3. RequiredFieldValidator Class Additional Properties
Method Type Description
InitialValue String Used to describe the initial value of the ControlToValidate . This is used to account for a default non-null value that should not be accepted, such as "Enter name here".

Note that if the InitialValue property is set, the RequiredFieldValidator will not be triggered by an empty (null) value in the ControlToValidate control. Basically, this validator simply compares InitialValue with the validated control's value, and if the two are the same, the validator concludes that the control is invalid.

Because we have already used this validator in an example, we will jump ahead to the next validation control before showing another example. The other validation controls are much more interesting than the RequiredFieldValidator , and we will see that by using these validators in concert, we are able to easily perform complex validation tasks that would have been very difficult, or at least tedious and time-consuming , using Classic ASP.

I l @ ve RuBoard


Asp. Net. By Example
ASP.NET by Example
ISBN: 0789725622
EAN: 2147483647
Year: 2001
Pages: 154

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net