Visual Studio Web Developer Tutorial Corner

Creating a vs webpage? Need some help?

Using Localization in the MasterPage and other pages (VB-sample) - Part 2

Posted by BottOm on October 2, 2007

The following steps are pretty easy. In Part 1 I explained how to set up the MasterPage and other pages by creating a BasePage.vb file and using a cookie and sessionobject. Your site should now be ready to use localization.
Part 2 is about adding resourcefiles and using those resources on the different pages (including your MasterPage).

Haven’t read Part 1? Then you have missed something!

Step 1. Folders for your resources

In your solution, you can have 2 different resourcefolder: App_GlobalResources and App_LocalResources. You can add them by rightclicking the solutionfile and choosing “Add ASP.NET Folder”.

The folder GlobalResources is used for resources available to the whole website. I use it for storing my sitemapresources (a detailed tutorial about this feature is on my to-do list).
Naming your global resource files:
name.language.resx or
name.language-culture.resx

LocalResources are used to store items used for a single page or control.
Naming your local resource files:
pageOrControlName.extension.language.resx or
pageOrControlName.extension.language-culture.resx

Step 2. Adding resourcefiles

Say you have 2 languages in your dropdownlist created in Part 1. English, which is the default language and French.
Then create the following files for your MasterPage:
MasterPage.master.resx (default)
MasterPage.master.fr.resx (French)
For the homepage:
Home.aspx.resx
Home.aspx.fr.resx

Every resource in those resx-files has to have a Name and a Value.
Place an asp-label named lblWelcome on your homepage (or MasterPage or other page, the principle is the same so I will only discuss it once).
In the resx-file for the English page type lblWelcome.Text as Name and Welcome as Value. For the French version typ: lblWelcome.Text and Bienvenue as Value.

Step 3. Last step

Change in the aspx-file for your website (eg. Home.aspx) the text of your labelcontrol: from Text=”" to Text=”<%$ Resources:lblWelcome.Text %>”.
It should look similar to this:

<asp:Label ID=”lblWelcome” runat=”server” Text=”<%$ Resources:lblWelcome.Text %>” />

Code sample:

Download the code sample for this tutorial here.
Please report any bugs or problems, it hasn’t been tested on another computer.

End note:

You have (hopefully) succesfull completed the tutorial and are ready to use localization throughout your website!

If you have any remarks or suggestions, please feel free to comment this topic.

5 Responses to “Using Localization in the MasterPage and other pages (VB-sample) - Part 2”

  1. Andrei Petrut Says:

    Hi. I tried to implement you solution, but I get an error in the BasePage class at runtime, when checking for Session variable. It says it doesn’t exist !

  2. BottOm Says:

    What name did you give your sessionvariable? Make sure it’s the same name everywhere it’s used.

    Maybe you can try adding these lines to the InitializeCulture-method of the basepage:

    If Session(”yourSessionName”) Is Nothing Then
    Session(”yourSessionName”) = “en”
    End If

    Anyways, I started creating a codesample this weekend which is almost finished now.
    So you’ll soon have a live and working sample.

    I’ll try to post it asap ;)

  3. Using Localization in the Masterpage (VB-sample) - Part 1 « Visual Studio Web Developer Tutorial Corner Says:

    [...] (RSS) « Enabeling IntelliSense in a Skinfile Using Localization in the MasterPage and other pages (VB-sample) - Part 2 [...]

  4. nurneync Says:

    Hello guys
    Wasjust serfing on net and found this site…want to say thanks. Great site and content!

  5. Audrey Bartlett Says:

    reticuloramose ferie hoven pharyngolaryngeal scientific nigritudinous denucleate muhlenbergia
    Caratheodory
    http://www.shelsgarden.com/kitchen.html

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>