Validation QuickStarts

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

The Validation Application Block QuickStarts are two applications, a Windows Forms example and a Web Forms (ASP.NET) example, that provide the same features and functionality even though they use different presentation technologies. They share the same business logic and other components, and demonstrate some of the key features of the Validation Application Block. Figure 1 shows the Windows Forms QuickStart application, and Figure 2 shows the Web Forms (ASP.NET) QuickStart.

Ff649963.48293d1f-df44-4984-83fc-a12a00dd5200(en-us,PandP.10).png

Figure 1
The Windows Forms QuickStart

Ff649963.4d1c31cc-bd7d-4992-afd2-101f89983843(en-us,PandP.10).png

Figure 2
The Web Forms (ASP.NET) QuickStart

The QuickStart walkthroughs are implementations of the Key Scenarios for the application block, and illustrate the following:

Building and Running the QuickStarts

The QuickStarts ship as source code, which means you must compile them before running them. You use Visual Studio to build the QuickStarts.

To build the Validation QuickStarts

  1. Ensure the Enterprise Library Source Code is installed.
  2. Open the Enterprise Library Source Code folder in Windows Explorer or from the Start menu. To open it from the Start menu, click Start on the taskbar, point to All Programs, point to Microsoft patterns & practices, point to Enterprise Library 4.0 — May 2008, and then click Enterprise Library 4.0 Source Folder.
  3. Open the QuickStarts folder, open the Validation folder, and then open the CS folder (for C#) or VB folder (for Visual Basic .NET).
  4. To run the ASP.NET QuickStart, open the ValidationAspNetQuickStart folder and double-click the solution file ValidationAspNetQuickStart.sln.
  5. To run the Windows Forms QuickStart, open the ValidationQuickStart folder and double-click the solution file ValidationQuickStart.sln.
  6. Visual Studio opens, displaying the solution file. On the Build menu, click Rebuild Solution. By default, this is a debug build.
  7. Press F5 to run the QuickStart.

QuickStart Configuration

The walkthroughs in the Validation QuickStarts include predefined configuration files, which are located in the main folder of each respective project. The ValidationAspNetQuickStart application configuration settings are stored in the standard Web.config file. For logistical reasons, the ValidationQuickStart application has two different configuration files, Designtime.App.config and Runtime.App.config. Make all configuration changes to Designtime.App.config, because Runtime.App.config is not intended to be directly edited.

Validation Rule Set Definitions

Validators can be applied to classes in two ways, either through configuration files or by applying attributes to class members. In the Validation QuickStart applications, these approaches are demonstrated by two rule sets: "RuleSetA" and "RuleSetB."

"RuleSetA" has been defined by applying attributes to members of the Customer and Address classes in the ValidationQuickStart.BusinessEntities project. "RuleSetB" has been defined using configuration, in the file ValidationQuickStart.BusinessEntities.dll.config. This configuration is loaded into the Windows Forms and ASP.NET QuickStarts using a FileConfigurationSource defined in the Runtime.App.config and Web.config files, respectively.

The Windows Forms QuickStart also includes a file Designtime.App.config, which uses a different relative path to the ValidationQuickStart.BusinessEntities.dll.config, allowing the configuration to be edited during design time.

The ValidationQuickStart.BusinessEntities and ValidationQuickStart.CustomValidator sub-projects are referenced by both of the validation QuickStart applications. Thus, changes made to the sub-projects are reflected in both the ASP.NET and Windows Forms QuickStart versions.

Configuration Settings

This section lists the configuration settings for the Data Access Application Block and the Validation Application Block used in the QuickStarts.

Data Access Application Block Configuration

The default connection string is configured as follows:

  • Name: LocalSqlServer
  • ProviderName: System.Data.SqlClient

Validation Application Block Configuration

The Address class is configured as follows:

Name: Address

City

  • String Length Validator
  • Contains Characters Validator
  • Not Null Validator

Line 1

  • String Length Validator 1+

Line 2

  • Or Composite Validator

The Customer class is configured as follows:

Address

  • Object Validator

DateOfBirth

  • Date Range Validator

Email

  • Regex Validator

FirstName

  • String Length Validator

LastName

  • Or Composite Validator

RewardPoints

  • Divisible By 10

To change or view these settings, use one of the Enterprise Library configuration tools to open the configuration file in the directory that contains the QuickStart project file. Each time you build the Windows Forms example, Visual Studio copies the configuration file to the output directory for the project (the same directory where the QuickStart executable is created), and renames it to ValidationQuickStart.exe.config.

This means that if you want to use the configuration tools to change any of the configuration settings, and you are planning to rebuild the solution, you must change the settings by opening the App.config file located in the QuickStart source directory. You can use the configuration tools to open the ValidationQuickStart.exe.config file and change the application configuration. However, these changes will be overwritten during the next successful build.