Enterprise Library Validation Application Block Message Template Tokens

Enterprise Library Validation Application Block Message Template Tokens

by David Hayden ( Sarasota Florida .NET Developer ), Filed: Enterprise Library 3.0

 

Message Template Tokens in the Validation Application Block are an absolute life saver when creating custom error messages for validation. When you combine the Message Template Tokens with Resource Files you get some serious maintainability pleasure in your applications.

The code below hardcodes the error message which is less than ideal:

 

[StringLengthValidator(1, 200,
    MessageTemplate = "Invalid Name, 1 - 200 Characters."]
public string Name
{
    get { return _name; }
    set { _name = value; }
}

 

This example uses Message Template Tokens {x} that are part of the Validation Application Block. Each validator has specific tokens that are described in the documentation:

 

[StringLengthValidator(1, 200,
    MessageTemplate = "Invalid {1}, {3} - {5} Characters."]
public string Name
{
    get { return _name; }
    set { _name = value; }
}

 

Combine the Message Template Tokens with Resource Files and you get a pretty deadly combination. I talk more about the topic in-depth here:

Validation Application Block Message Template Tokens and Resource Files

 

Absolute wonderful idea that saved me a lot of work!

News Feed: David Hayden ( Sarasota Florida .NET Developer )

Filed: Enterprise Library 3.0

posted on Saturday, April 28, 2007 4:52 PM

Main

David Hayden Google +

David Hayden Twitter

Health & Fitness

JavaScript Patterns Book Review

HTML 5 and CSS3 - Develop with Tomorrow's Standards Today

Professional ASP.NET Design Patterns Book Review

Beginning Mac Programming Book Review

C# in Depth Book Review

ASP.NET MVC

Orchard CMS

Categories