Validating User Input in ASP.NET
Posted on September 17, 2007 - Filed Under ASP.NET |
Part I.
This is the first part of our web tutorial on how to validate user input in asp.net. In this tutorial we are targetting to achieve the following objectives:
1. Understanding the use and implementation of ASP.NET validation controls.
2. Using server- and client-side validation with ASP.NET.
3. Building our own custom validation controls.
One of the most tedious and time-consuming activities for a developer is the validation of user inputs especially when developing applications that put heavy emphasis on end-user data. Amazingly, ASP.NET provides a series of controls that can perform both client-side and server-side validations. These controls include the following:
1. The RequiredFieldValidator control which insures that a user either provides a value for a control or in some way modifies the initial values of a control.
2. The CompareValidator control which checks to make sure a control contains a specific value or matches the value contained in a second control.
3. The RangeValidator control which ensures that the user-provided value for a control falls within a specified range, or that the value falls within a range specified by other form controls.
4. The RegularExpressionValidator control which supports the use of regular expressions to validate control values, providing an extensively flexible technique for validating credit card numbering sequences, email-addresses, or any other consistent expressions.
5. The CustomValidator control which enables the developer to define any server- or client-side function to validate against, therefore covering any remaining validation not provided for in the first four controls.
6. The ValidationSummary control which allows you to collect all of the validation errors and provide a consolidated listing to the user.
The use of these embedded controls enables us to eliminate many lines of custom client-side code that we have developed or will develop to perform many of these rudimentary validations. Additionally, we will receive the benefit of building upon these basic validation controls to build our own custom validation controls for handling any number of recurring validation tasks.
That’s it for now, we will continue on the Common Aspects of Validation Controls in my next blog tutorial…
Reference: ASP.NET Database Programming Weekend Crash Course by Jason Butler and Tony Caudill
Comments
Leave a Reply