O'Reilly logo

.NET Framework 4.5 Expert Programming Cookbook by A.P. Rajshekhar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extending the validation attribute for localization

If you do not want to hardcode the message or embed it as a resource, the only approach left is to extend the attribute so that messages can be decided at runtime based on the locale used. Extending an attribute for this purpose can also help if you decide to fetch the message from the database or an external translation service.

In this recipe, we will modify the UniqueUserValidator code so that it can generate locale-based custom messages. The custom messages will be fetched from an XML file using the logic developed in the previous recipe.

How to do it...

The following steps will guide you as you generate locale-based custom messages:

  1. Open CustomValidation.sln in Visual Studio .NET 2012.
  2. Open ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required