Victor
Victor

Reputation: 953

asp.net resource customization

Our web site( ASP.NET 4.0 ) makes heavy use of meta:ResourceKey in each control throughout for pretty much anything you can see on a page and is customized from client to client. But the problem is that resource sometimes needs to be customized from client to client. For example if there is this string in a resource file Label1ResourceText.Text = 'Welcome to Customer1 site' then it needs to be changed to Label1ResourceText.Text = 'Welcome to Customer2 site' both in English and localized resource versions of the app when we install Customer2 version. I am wondering if it can be done with minimal customization work between each customer either programmatically or declaratively but without having to manually edit or produce different resource files for each customer. Thanks for the suggestions.

Upvotes: 1

Views: 109

Answers (2)

Maciej
Maciej

Reputation: 2185

Whether you use a single file or multiple files, your website will still have to determine which file to use or which key to use if you go with a single file approach.

Other than that, you will have to use two separate files.

An alternative would be to add a single resource file, say UIStrings.resx, to the resources folder. You could then store the following string in the resource file

WeclomeMessage = "Welcome to {0} site"

Then you can render the string using

Label1.Text = String.Format(Resources.UIStrings.WelcomeMessage, CustomerName);

in the code behind.

As an alternative to the code behind approach is to use

<asp:Label Text="<%= String.Format(Resources.UIStrings.WelcomeMessage, CustomerName)%>" />

This link has some good information on how to utilize resource files.

Upvotes: 1

Alex Dn
Alex Dn

Reputation: 5553

Look at http://msdn.microsoft.com/en-us/library/ms227982(v=vs.100).aspx. You can use different resx files and call them based on your business logic programmatically.

Upvotes: 0

Related Questions