Data Validation

In addition to providing controls for data binding, Atlas ships with its own controls for validating data the user enters, a feature that many ASP.NET developers find useful. Atlas supports the following validators:


Checks whether the user has entered a value into a control


Checks the data in a control against a regular expression to match a pattern


Checks the data in a control against a data type


Checks the data in a control against a value range


Checks the data in a control using a custom validation function

To implement data validation, you need:

  • A control to validate

  • A way to display an error message if the validation fails

  • Code or markup to do the validation

In the following sections you’ll see how to put each of the Atlas validators to work, including how to do your own custom validation.

Checking a Required Field

The requiredFieldValidator class, which checks whether a control contains data, is a commonly used Atlas data validator. The following markup generates both an input field and a span to display any error messages that the validator generates:

<input type="text" id="TextBox1" />
<span id="Error1" style="color: red;">*</span>

As you can see, the label for the error message is not hidden by default. Atlas takes care of hiding it automatically.

In the xml-script for the page, add markup for the HTML elements taking part in the validation—just the elements, not any controls ...

Get Programming Atlas now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.