Download presentation
Presentation is loading. Please wait.
Published byDominic Ryan Modified over 8 years ago
1
Validation Controls Assist your users with providing the correct type of input for your application Assist your users with providing the correct type of input for your application What are some examples of validation algorithms that we might need to enforce in an e-commerce environment? What are some examples of validation algorithms that we might need to enforce in an e-commerce environment? Sometimes, client-side processing is better. Why is this? Sometimes, client-side processing is better. Why is this?
2
ASP.NET 2.0 Validation Provides rich controls for validating user input. Provides rich controls for validating user input. Can validate both HTML and ASP controls. Can validate both HTML and ASP controls. Are linked to controls by using the CausesValidation property (Boolean) in your web forms. Are linked to controls by using the CausesValidation property (Boolean) in your web forms.
3
Types of Validators 1. RequiredFieldValidator 2. RangeValidator 3. CompareValidator 4. RegularExpressionValid ator 5. CustomValidator
4
RequiredFieldValidator Link the validator to a control using the “ControlToValidate” property. Link the validator to a control using the “ControlToValidate” property. Next, include your error message. Next, include your error message.
5
CausesValidation Make sure the CausesValidation property for your button is set to “True.” Make sure the CausesValidation property for your button is set to “True.”
6
Example Form If the button is clicked with no text entered, the error message is displayed. If the button is clicked with no text entered, the error message is displayed.
7
Adding Additional Textboxes Simple add a new RequiredFieldValidator for each additional textbox. Simple add a new RequiredFieldValidator for each additional textbox.
8
The Summary Validator Useful if you want to provide a list of errors for the user. Useful if you want to provide a list of errors for the user.
9
Design View
10
A Real Application
11
The CompareValidator A more powerful type of validator is the CompareValidator. A more powerful type of validator is the CompareValidator.
12
CompareValidator Example Let’s use this to make sure the user has entered a numeric customer ID. Let’s use this to make sure the user has entered a numeric customer ID.
13
Other Uses for CompareValidator Compare a control to a constant. Compare a control to a constant. –When might this be useful? Compare a control to a database value. Compare a control to a database value. –Why would we do this? Compare one control to another. Compare one control to another. –What is an example usage?
14
RangeValidator Allows you to check for a range of values in input. Allows you to check for a range of values in input.
15
Sample Output
16
RegularExpressionValidator The most powerful type of validation control. Allows you to specify a precise pattern for describing and manipulating text. The most powerful type of validation control. Allows you to specify a precise pattern for describing and manipulating text. Uses literals (characters to match in the target string) and metacharacters (special symbols that act like commands for the regular expression parser). Uses literals (characters to match in the target string) and metacharacters (special symbols that act like commands for the regular expression parser).
17
Example Regular Expression The ValidationExpression property’s ellipses will open up a handy editor with many useful built-in regular expressions. The ValidationExpression property’s ellipses will open up a handy editor with many useful built-in regular expressions.
18
Example Setup Note the expression can seem quite complicated if you don’t know the patterns! Note the expression can seem quite complicated if you don’t know the patterns!
19
Example Output
20
Custom Validation What about when you need to write your own specific validation routines? Luckily, VB lets you create your own using the CustomValidator control. What about when you need to write your own specific validation routines? Luckily, VB lets you create your own using the CustomValidator control. When might we need to have this functionality? When might we need to have this functionality?
21
Client Handler Code
22
Server Handler Code
23
Validation Groups Used when you want certain groups of controls on your form to be validated together at the same time. Used when you want certain groups of controls on your form to be validated together at the same time. Why would this be handy at times in an ecommerce situation? Why would this be handy at times in an ecommerce situation?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.