HELP Pretty please :-)


Robert Dufour

I am trying to localize a very simple web site (english and french)

I have a master page and one content page for now.
On the master page I have placed a Localize control

On the content page I have placed a label and a dropdownlist. The label says
"Use this language" or "Utilisez cette laague"
The dropdownlist Contains values "en-US" text Englsih Us and "fr-CA" text
"French Canada)

I have resource files for the master page in english and french with a key
saying "welcome" value Welcome in english and Bienvenue in french resource
file. They are local resource files for the master.

The objective is to allow the user to switch languages by settting the
current threads UiCulture and Culture in code when the user selects another
language. When he -she changes language in the dropdown list , the content
of the master file localize control should change and the contents of the
content page should change.

I've been f.. around with this one for over two days but I can't get it
I have based my code on the code in the sample video on msdn for
localization but in this case just extending it to work with a master page
I've hit a brick wall :-(

Can someone PLEASE, prety please give a hand on this one.

This is the code I've come up with so far

1- the master page, just a standard masterpage with one localized control on

<%@ Master Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<script runat="server">


<html xmlns="">

<head runat="server">

<title>Untitled Page</title>



<form id="form1" runat="server">


<asp:Localize ID="LocWelc" runat="server" meta:resourcekey="Welcome"
Text="Welcome"></asp:Localize><br />

<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">






2- The content page - standard page with default culture and Uiculture set
tp fr-CA

<%@ Page Language="VB" MasterPageFile="~/Site.master"
AutoEventWireup="false" CodeFile="Default3.aspx.vb"

Inherits="Default3" Title="Untitled Page" Culture="fr-CA"

<%-- Add content controls here --%>

<asp:Content runat="server" ID="d3C"


<asp:Label ID="Label1" runat="server" Text="<%$ Resources:Label1.Text

<asp:DropDownList ID="Language1" runat="server" AutoPostBack="True"

<asp:ListItem Value="fr-CA">Français (Canada)</asp:ListItem>

<asp:ListItem Value="fr-FR">Français (France)</asp:ListItem>

<asp:ListItem Value="en-CA">English (Canada)</asp:ListItem>

<asp:ListItem Value="en-US">English (US)</asp:ListItem>



3- The code behind of the content page

Imports System.Threading

Imports System.Globalization

Partial Class Default3

Inherits System.Web.UI.Page

Protected Overrides Sub InitializeCulture()

If Request.Form.Item("Language1") IsNot Nothing Then

Dim Lang As String = Request.Form.Item("language1")

Thread.CurrentThread.CurrentCulture = _


Thread.CurrentThread.CurrentUICulture = New _


End If

End Sub

End Class

All the controls on both master and content page have had their expressions
text property set to point to the appropriate key in the resource file.

The main problem appears to be that no matter what, when I change the
selection in the drop down list the variable Request.Form.Item("Language1")
always returns nothing I can never obtain the value of the dropdownlist
selected item.

I can get it to detect the selected language if I detect it in the selected
index changed event of the language1 control but this event fires well after
the Initialize culture event, so If I use that I am always using the
previously selected item not the one that is currently being selected.

The technique described above with the code in the code behind works OK in
a stand alone content page but it fails miserably when you make a content
page that uses a master page. I have not been able to find any sample code
on how to use this with master pages.

The second part of the question, sorry if its long, is how do you change the
value of the localize control on the master page when the user selects
another language in the content page?

I am realy desperate and would really appreciate any help anyone would be
kind enough to give

Thanks you in advance to all


Cowboy \(Gregory A. Beamer\)

Check where you have the resource files. It matters.

I would read Michele Bustamante's first article for more info on
meta:resourcekey versus attaching resources using other declarative means of
linking to local/global resources.

This article is also great if you want to move to external resources or

Her blog ( has some great globalization/localization

Robert Dufour

I've read the article and been to her web site seing the globalization
samples and copied and studied the web one , but I still don't see why the
Request.Form.Item("Language1") always returns nothing when used in a web
site with master page but detects the control value OK when a master page
is not involved.
That seems to be the crux of the problem, the code does not find the control
Language1 on the web page, when its in a page that uses a master but it
finds it OK in a simple web page. Why and how to fix it?


View the source of the page in the browser, and you will see that the
name of the field is not what you expected. When a control is inside a
container like the Content control, it's id is changed to ensure that
it's unique.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Latest member

Latest Threads