CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

David Hayden [MVP C#]

         .NET Tutorials, Patterns, and Practices

Validation Application Block ASP.NET Integration Example Download - Jan 2007 CTP

One more example you can download associated with the Enterprise Library 3.0 Validation Application Block Presentation I gave at the South Florida Code Camp.

One of the really cool features in the Validation Application Block is the ASP.NET and Winform Integration so you don't have to specify redundant validation rules both at the UI and within the business layer. The Validation Application Block comes with web and winform controls that allow the UI to get its validation rules from the business layer, saving you the headache of duplicating validation rules in multiple places.

Many of you attending my presentation were intrigued by the integration functionality, so I have uploaded an example of the Validation Application Block and ASP.NET Integration. Below is an snapshot of the running demo:

 

 

My goal was to keep things really simple so you can see how easily you can integrate the Validation Application Block into your websites. If you look at the Visual Studio 2005 Solution:

 

 

The website includes a single Subscriber Class in the App_Code Folder that contains the validation rules in Attribute Form.

When you look at the visual designer surface for the the AddSubscriber.aspx Page, the form contains PropertyProxyValidator Web Controls that come with the Validation Application Block. The web controls look at the ValidatorAttributes on the Subscriber Class to provide validation to the UI.

 

 

The Subscriber Class looks as follows:

public class Subscriber
{
    private string _name;
    [NotNullValidator(MessageTemplate = "Name cannot be null.")]
    [StringLengthValidator(1,100,MessageTemplate = "Max 100 characters.")]
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }

    private string _emailAddress;
    [NotNullValidator(MessageTemplate = "EmailAddress cannot be null.")]
    [StringLengthValidator(1, 100, MessageTemplate = "Max 100 characters.")]
    [RegexValidator(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", MessageTemplate = "Invalid.")]
    public string EmailAddress
    {
        get { return _emailAddress; }
        set { _emailAddress = value; }
    }

    public Subscriber() {}
}

 

I hope the example download helps. As I demonstrated during the presentation, the Validation Application Block provides similar functionality in the winform environment.

Next I will be presenting at the Orlando Code Camp on March 24th. The topics are:

  • Enterprise Library 3.0 – New and Improved!
  • Build Your Own Application Blocks for Enterprise Library
  • Build Better Websites Faster Using the Web Client Software Factory

 

Validation Application Block Tutorials and Resources:

  • Business Object Validation Using Validation Application Block - Self Validation Option - Enterprise Library 3.0
  • Validation Application Block - Business Layer and Data Access Layer Integration - Enterprise Library 3.0
  • Validation Application Block in Enterprise Library 3.0 - Using Validation Facade Class - Part I
  • Validation Application Block in Enterprise Library 3.0 - ValidationFactory Class - Part II
  • Validation Application Block Ruleset in Enterprise Library 3.0 - Enterprise Library 3.0 Tutorials - Part III
  • Validation Application Block - Rules in External XML Configuration File - App.Config Web.Config - Enterprise Library 3.0 - Part IV
  • by David Hayden

     



    Comments

    Christopher Steen said:

    .NET Micro Framework SDK [Via: The Moth ] An Overview of Cryptographic Systems and Encrypting Database...

    # February 14, 2007 10:54 PM

    Mike said:

    Can you replace Web Client Factories entlib2 with entlib3? Is that what you did for these demos to use Validation Block?

    # February 14, 2007 10:57 PM

    David Hayden said:

    I haven't tried using the Validation Application Block with the Web Client Software Factory. I suspect it will not work, but I will give it a try this weekend and see if my suspicions are correct.

    In the Validation Application Block example I am just using the theme and master page of the WCSF, but not the actual factory itself.

    # February 16, 2007 11:48 AM

    Steven J. Ackerman said:

    This was one of the neat features that you demoed at the Sarasota Developers meeting in January. Thanks for putting it on your blog - I had kind of forgotten about it.

    # February 16, 2007 12:26 PM
    Check out Devlicio.us!

    Our Sponsors

    This Blog

    Syndication

    News

    CodeBetter.Com Home