Talk to Webmaster Tony John
Resources » .NET programming » .NET Framework
Data Validation Controls in ASP.NET 2.0 Part 1
ASP.NET 2.0 offers a wide variety of ways to capture user input. This translates to, many opportunities for users to provide bad data. In this article, you will learn about the support that ASP.NET provides to you for performing data validation.
Often, bad data doesn't affect your organization until someone tries to report against it or some business intelligence project uncovers the presence of inconsistencies. If bad data is discovered in these circumstances, correcting it is an overwhelming, if not impossible, task. There could be millions of records with inconsistent and erroneous information. All these instances will skew your reports and make your business intelligence efforts more ambiguous.
So that you can avoid correcting bad data, you must validate data at the time of entry and, thereby, prevent bad data from getting into your systems. ASP.NET 2.0 provides some excellent support for performing data validation. In this article, you will see, choosing an appropriate data validation technique and then how to implement that technique using the intrinsic ASP.NET 2.0 data validation controls.
Appropriate Data Validation Technique
In a multi-tier architecture, the input source is not restricted to the UI and presentation layers. Data can come from many different sources such as other internal systems, other external systems, and other components of the same system. In this situation, it is not sufficient to rely solely on the presentation layer for validation.
On the other hand, if your application receives its input exclusively from the UI, then you can rely solely on the UI to validate the input data. In this article, we will mainly focus on validating data provided via a Web-based UI.
Validation Controls Common Properties
It should be no surprise that ASP.NET provides a solid base of validation controls. You can use these flexible controls out of the box or build on them through inheritance to create your own validation controls.
All ASP.NET validation controls have some common properties with which you should be familiar. The following listing describes the common properties among validation controls.
ControlToValidate: This property is used to indicate which control the validation control is to validate.
Display: This property provides three possible values. Setting the property to None prevents the control from being displayed inline. Use this setting in conjunction with the ValidationSummary control. The Static setting renders the validation control inline with other controls. This means that blank space is occupied by the control when it is not showing a message. Use the Dynamic setting when you want to avoid the control occupying blank space.
Enabled: This property determines whether the validation control actually performs validation.
ErrorMessage: This property is generally associated with the ValidationSummary control.
ForeColor: Use this property to set the color of the inline error message when validation fails.
IsValid: This property is used to evaluate whether validation fails.
SetFocusOnError: Setting this property to True causes the focus to be set to the control identified in the ControlToValidate property if validation fails.
Text: The Enabled property determines whether the validation control actually performs validation. The Text property is generally associated with the inline messageâ€“the message displayed at the location of the validation control.
ValidationGroup: Validation groups are new to .NET 2.0. This property is used to associate the current validation control with a specific validation group.
Now that you have been introduced to the common attributes of validation controls, you can dig deeper into specific facets of each validation control. You can use validation controls in combination. For example, you can use RequiredFieldValidator and RegularExpressionValidator controls on the TextBox control for capturing an e-mail address.
In Next article we will talk about all the validation controls.
FYI: (this is my article which is also published in another site)
Did you like this resource? Share it with your friends and show your love!
No responses found. Be the first to respond...
Active MembersTodayLast 7 Daysmore...