The ASP.NET environment provides developers with many tools for speeding up the development process. Developers often spend a lot of time writing code which checks the data entered by the user in a web form. ASP.NET validation server controls cut down development time by removing the need to write complex validation code to handle client-side and server-side validation of information entered into a form by a user. The controls do more than just validation; they also perform browser detection to check whether JavaScript is enabled on the client’s browser. If JavaScript is enabled, the control sends the necessary JavaScript code to the client; if JavaScript is not enabled, server-side validation takes place.
ASP.NET offers developers six validation controls available in ASP.NET: the RequiredFieldValidator, the CompareValidator, the RangeValidator, The RegularExpressionValidator, The CustomValidator and the ValidationSummary.
The most frequently used and the most basic is the RequiredFieldValidator. It simply prevents the user from submitting the form without first entering or choosing a value in a required form field. It is often used in conjunction with other validators since, naturally, multiple validators may be applied to the same field.
Next, we have the CompareValidator which performs comparison on the contents of a given form field and another element. The type of comparison can be varied to reflect the type of data the field contains. Thus, for example, if the data is numeric, operators such as equal to, greater than and less than can be used. The comparision will often involve two fields. For example, if your form requests the user’s email address twice to ensure that it has been entered correctly, the CompareValidator can be used to check that the two email address fields contain the same entry.
The RangeValidator performs a special type of comparison; it verifies that the value entered by the user falls within a certain range. It can be used to perform checks within text ranges, number ranges and date ranges.
The RegularExpressionValidator allows you to define a regular expression against which the value entered in a field can be validated. Regular expressions are a widely-used standard for checking that a given string conforms to a certain pattern. They are notoriously arcane but Visual Studio and Visual Web Developer Express make the process easy by providing a Regular Expression Editor which contains regular expressions for matching common types of data such as email address, web URLs as well as postcodes and telephone numbers for several different countries.
The CustomValidator control offers maximum flexibility in performing validation checks, allowing developers to write custom validation code. The code may be client-side or server side.
The final validation server control, the ValidationSummary control is not itself used for validation. Instead, it works in conjunction with the other controls to provide a mechanism for consolidating error messages generated by other validation controls. It is particularly useful for large forms.
Need to master web development using ASP.NET? We offer Microsoft ASP.NET training courses in London and all over the UK.
Possibly related posts: (automatically generated)
- Related posts on asp.net
- Going from ASP.NET to PHP/Drupal : Part 2 « Improper Syntax
- Freelance .NET Developer « new media monthly
- Related posts on computer tips
- Cindi Gay Rug Hooking » Don't Miss the Last Step – Label Your Rugs
- Computer Maintenance Tips : How to Use Your TV as a Second Monitor …
- Random Computer Blogging « Computer Safety Tips
- Related posts on Computers
- Employees Can Buy Computers From Employers at a Discounted Rate …
- Google demos image rec 'quantum computer' (The Register)
- Geeks Drive Girls Out of Computer Science (LiveScience.com via …