ASP.NET Validation Server Controls

Getting the forms that are present on your Web pages to deal with validation is a common task in web development. For this reason, with the initial release of ASP.NET, the ASP.NET team introduced a series of validation server controls meant to make implementing sound validation for forms a snap.
ASP.NET not only introduces form validations as server controls, but it also makes these controls rather smart. As stated earlier, one of the tasks of classic ASP developers was to determine where to perform form validation – either on the client or on the server. The ASP.NET validation server controls eliminate this dilemma because 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.
The best part about this scenario is that 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. This decisive nature of the validation server controls means that you can build your ASP.NET Web pages to be the best they can possibly be — rather than dumbing – down your Web applications for the lowest common denominator.
Presently, seven validation controls are available to you in ASP.NET 4.0 No new validation server controls have been added to ASP.NET since the initial release of the technology, but ASP.NET 2.0 introduced some new features, such as validation groups and new JavaScript capabilities. The available validation server controls include:

  • RequiredFieldValidator
  • CompareValidator
  • RangeValidator
  • RegularExpressionValidator
  • CustomValidator
  • DynamicValidator
  • ValidationSummary

Working with ASP.NET validation server controls is no different from working with any other ASP.NET server control. Each of these controls allows you to drag and drop it onto a design surface or to work with it directly from the code of your ASP.NET page. You can also modify these controls so that they appear exactly as you want – ensuring the visual uniqueness that your applications might require.

Validation Server Control Description
RequiredFieldValidator Ensures that the user does not skip a form entry field.
CompareValidator Allows for comparisons between the user’s input and another item using a comparison operator (equals, greater than, less than, and so on).
RangeValidator Checks the user’s input based upon a lower- and upper-level range of numbers or characters.
RegularExpressionValidator Checks that the user’s entry matches a pattern defined by a regular expression.This control is good to use to check e-mail addresses and phone numbers.
CustomValidator Checks the user’s entry using custom-coded validation logic.
DynamicValidator Works with exceptions that are thrown from entity data models and extension methods. This control is part of the ASP.NET Dynamic Data Framework.
ValidationSummary Displays all the error messages from the validators in one specific spot on the page.
Tagged , . Bookmark the permalink.

Leave a Reply