The example you found is not a very good one. The correct place to set the culture in ASP.NET is to override the method InitializeCulture
. I normally implement that method in a common base class for all my web forms.
You could implement something like this:
protected override void InitializeCulture()
{
if (Session["locale"] != null)
{
string selectedLanguage = Session["locale"];
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
}
base.InitializeCulture();
}
Somewhere you have to store the selected language in the Session variable, e.g. like this:
Session["locale"] = langDropdown.SelectedValue;