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.

Ff647082.ed84635d-b70f-4cf1-8cbf-55cd3d754688(en-us,PandP.10).png

Figure 1
The Windows Forms QuickStart

Ff647082.c3f0555d-13b8-4daa-b7d8-cf3f5e7e150e(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.1 — October 2008, and then click Enterprise Library 4.1 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

    Property

    Value

    Data Source

    .\SQLEXPRESS

    Integrated Security

    SSPI

    AttachDBFilename

    |DataDirectory|aspnetdb.mdf

    User Instance

    True

Validation Application Block Configuration

The Address class is configured as follows:

Name: Address

  • City
    • String Length Validator

      Property

      Value

      LowerBound

      1

      LowerBoundType

      Inclusive

      Negated

      False

      UpperBound

      30

      UpperBoundType

      Inclusive

    • Contains Characters Validator

      Property

      Value

      CharacterSet

      1234567890!@#$%^&*()-=

      ContainsCharacters

      Any

      Negated

      True

      MessageTemplate

      City may not contain numbers or punctuation characters

    • Not Null Validator

      Property

      Value

      Negated

      False

  • Line 1
    • String Length Validator 1+

      Property

      Value

      LowerBound

      1

      LowerBoundType

      Inclusive

      Negated

      False

      UpperBound

      0

      UpperBoundType

      Ignore

  • Line 2
    • Or Composite Validator

      Validator

      Property

      Value

      String Length Validator : 0-50

      LowerBound

      0

      LowerBoundType

      Inclusive

      Negated

      False

      UpperBound

      50

      UpperBoundType

      Inclusive

      Null Validator

      Negated

      True

      The Customer class is configured as follows:

      • Address
        • Object Validator

          Property

          Value

          TargetRuleSet

          RuleSetB

      • DateOfBirth
        • Date Range Validator

          Property

          Value

          LowerBound

          1/1/1969

          LowerBoundType

          Inclusive

          Negated

          False

          UpperBoundType

          Ignore

          MessageTemplate

          Must be born after 1969

      • Email
        • Regex Validator

          Property

          Value

          Options

          None

          Pattern

          \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

          MessageTemplate

          Invalid e-mail address

      • FirstName
        • String Length Validator

          Property

          Value

          LowerBound

          0

          LowerBoundType

          Ignore

          Negated

          False

          UpperBound

          20

      • LastName
        • Or Composite Validator

          Validator

          Property

          Value

          Starts with X RegEx Validator

          Options

          None

          Pattern

          X.*

          MessageTemplate

          Last name must start with "X"

          Ends with z RegEx Validator

          Options

          None

          Pattern

          z*.

          MessageTemplate

          Last name must end with "z"

          - **RewardPoints** - **Divisible By 10**

          Property

          Value

          Collection

          Key: Divisor, Value: 10

          Tag

          Warning

          Type

          ValidationQuickStart.CustomValidators.DivisibleByValidator, ValidationQuickStart.CustomValidators,

          Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

          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.