ASP.NET Validation Controls


Presently, ASP.NET has  six smart validation controls in .NET 3.5.


These controls are called smart valdiation controls because they can perform validation both on client side and server side.


ASP.NET performs browser detection when generating the ASP.NET page and makes decisions based on the information it gleans.


This means that if the browser can support the JavaScript that ASP.NET can send its way, the validation occurs on the client-side. If the client cannot support the JavaScript meant for client-side validation, this JavaScript is omitted and the validation occurs on the server.


Even if client-side validation is initiated on a page, ASP.NET still performs the server-side validation when it receives the submitted page, thereby ensuring security won’t be compromised.


The available validation server controls  are
 Validation Control  Description
 RequiredFieldValidator  Checks that the control it has to validate is not empty when the form is submitted.
 RangeValidator  Checks that the value of the associated control is within a
specified range. The value and the range can be numerical, a
date or a string.
 CompareValidator  Checks that the value of the associated control matches a
specified comparison (less than, greater than, and so on)
against another constant value or control.
 RegularExpressionValidator   Checks if the value of the control it has to validate matches the specified regular expression.
 CustomValidator  Allows you to specify any client-side JavaScript validation
routine and its server-side counterpart to perform your own
custom validation logic.
 ValidationSummary  Shows a summary with the error messages for each failed
validator on the page (or in a pop-up message box).


The BaseValidator Class

The validation control classes are found in the System.Web.UI.WebControls namespace and inherit from the BaseValidator class.

This class defines the basic functionality for a validation control.