I have successfully implemented a multi-language website in which user can change language by clicking one of the imagebuttons. I used a Hiddenfield to store code of language that was selected by the user (on Imagebutton click event). My InitializeCulture method looks like this:
protected override void InitializeCulture()
{
string culture = "Auto";
string selectedValue = Request.Form["ctl00$HiddenFieldLang"];
switch (selectedValue)
{
case "1": culture = "Auto";
break;
case "2": culture = "zh-HK";
break;
default: break;
}
if (culture != "Auto")
{
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(culture);
//ci = System.Globalization.CultureInfo.CreateSpecificCulture(culture);
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
}
base.InitializeCulture();
}
This works fine. But it takes 2 postbacks to change the language of the page. I'm guessing, in one postback (which changes nothing), the hiddenfield's value is set. In second postback, actual translation takes place.
How do I implement it so that the page is translated in just one click of imagebutton?
Thanks!!