I am using Visual Studio 2008 and ASP.NET to build a web application. Most of my web pages are based on one main page. This main page contains three buttons that act as language switches; Click event handlers look like this:
protected void lbuLangEN_Click(object sender, EventArgs e) { this.SwitchLanguage(string.Empty); } protected void lbuLangES_Click(object sender, EventArgs e) { this.SwitchLanguage("es"); }
Then I have my private SwitchLanguage method:
private void SwitchLanguage(string culture) { Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture); }
As far as I understand, this should be enough so that pages based on my main page exhibit localized behavior, i.e. got their resources from the corresponding local resx file according to the culture. However, it does not work. They always appear in Spanish, this is my default browser. I set some trace messages at SwitchLanguage entry and exit points, and apparently the current thread does not change its culture information: every time SwitchLanguage is called, the current thread culture is "es-ES", regardless of what my code only what is installed.
Are there any problems with my code or with the approach I take? Thanks.
source share