NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Special-Case Validation Results

Validation ensures that what the user has entered meets criteria that you specify. In most cases, this is a straightforward operation. However, at times the situations under which input is validated introduce special conditions. It is important that you understand what those conditions are, how validation is performed, and what the results of a validation attempt can be.

Validating Required Fields

If validation is being performed exclusively on the server, then a required field will be checked only when the form is submitted. It might therefore appear during data entry as if the user is able to skip the field. Under most circumstances, this isn't a problem, since all other validation is also occurring on the server. However, if you have client script that relies on a value in a required field, the RequiredField validation control won't be able to ensure that there is a value in the field.

If client-side validation is being performed, the user can skip over a required field. However, once a value has been entered into the field, the user cannot clear that value without generating an error.

Comparing Against Blank Fields

Other than the RequiredFieldValidator control, validation controls consider a field valid if it is blank. For example, if you attach a RangeValidator control to a date field, validation passes either if the user enters a date in the specified range or if the field is left blank. If you want to ensure that the user enters a date, you must add a RequiredFieldValidator control to the control along with the range check.

Comparing Against Another Control

When using the CompareValidator or RangeValidator controls, you can specify that validation be performed against the value of another control. For example, you might have two fields for entering dates, a start date and an end date. Using a RangeValidator control, you can ensure that the minimum value for the end date is the value of the start date.

If the validation controls are unable to resolve the value in the other control, they do not raise an error; instead, the validation check passes. This might occur if:

The specific tests and results performed by these controls are:

This strategy prevents multiple errors from being reported for the same invalid entry. Validation controls are designed to test and report on only one value and to be able to able to display as precise a message as possible when an error is encountered.

For example, in the example of the end date, imagine that the user entered an invalid start date. The user then enters an end date. When the validation check is performed (usually on the server), the same bad date could potentially raise an error both for the start date field and for the end date. To prevent this from occurring, the end date validation — the validation dependent on another field — does not raise an error.

You should therefore ensure that you provide sufficient validation for each individual field. In the example, it would be up to you to make sure that the user has entered a proper date in the start date field. In many cases, you should include a RequiredFieldValidator control in addition to a validation control that tests the contents of a specific entry.

See Also

Validation Controls