How to change page localization with asp:DropDownList?
I have localized application where user can choose her preferred language in dropdown control. After OnSelectedIndexChanged event there is postback and CurrentThread.CurrentCulture should be set to what user chooses.
Login.aspx.cs
public partial class Login : BasePage
{
protected void LanguageDrop_changed(object sender, EventArgs e)
{
var lang = LanguageDropDown.SelectedValue;
Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
}
}
However, it does not work correct because LanguageDrop_click event fires after InitializeCulture so s开发者_StackOverflow中文版ome default culture is initialized, controls are localized to default language and then CurrentThread.CurrentCulture is set. So user have to refresh page once more to see them in chosen language.
UPDATE: I found partial answer: http://www.codeproject.com/Kb/aspnet/localizationByVivekTakur.aspx He retrieves language dropdown value in InitializeCulture() event from Form collection
The best answer is either link I provided
http://www.codeproject.com/Kb/aspnet/localizationByVivekTakur.aspx He retrieves language dropdown value in InitializeCulture() event from Form collection
or making Response.Redirect so page is requested again and then culture is set.
In my experience there's no better option unfortunately and you will have to perform another refresh. Your reasoning is correct.
精彩评论