Validation Application Block and ASP.NET Website Integration Sample - Enterprise Library 3.0
by David Hayden ( Microsoft MVP C# ), Filed: Enterprise Library 3.0
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:
Source: David Hayden ( Microsoft MVP C# )
Filed: Enterprise Library 3.0