To change the language I click on an imageButton which executes something like:
SetCulture(Session, "en-GB");
This function is implemented as follows:
public static void SetCulture(HttpSessionState session, string locale)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(locale);
Thread.CurrentThread.CurrentCulture = new CultureInfo(locale);
session["currentLocale"] = locale;
}
Also, my .aspx pages are of type LocalizedPage which overrides InitializeCulture:
protected override void InitializeCulture()
{
if (Session["currentLocale"] != null)
{
//changes the cultures of the current Thread
CurrentUICulture = new CultureInfo((string)Session["currentLocale"]);
CurrentCulture = new CultureInfo((string)Session["currentLocale"]);
}
base.InitializeCulture();
}
Now, the problem is that I have to click twice on the imageButton in order to make the language change. What can I do to change the language on the first click?
Note that I am rather new to ASP.NET so it might be a simple solution
InitializeCulture()is one of the first things that happen when a page is loaded:When you try to change the culture using a Button, that bit of code runs well into the page lifecycle, after the culture has been initialized.
The easiest way to get the culture to change in one click it to reload the page after
SetCulture()via a redirect to itself: