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!!
Thank you all for the replies.
I managed to solve this problem with the help of this link.
But I have another issue now.
I have a masterpage and I put the Hiddenfield and the Javascript function to set the value of hiddenfield in my masterpage. In the URL of all my pages, I have a querystring with the language id. So, whenever the language changes, I want to change the querystring as well.
Is there any way I can fetch the URL of current content page from the masterpage and do a Response.Redirect or Server.Transfer from SetHiddenValue(val) function itself and ensure that the text is translated?