Reputation: 10358
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 some 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
Upvotes: 2
Views: 5155
Reputation: 10358
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.
Upvotes: 1
Reputation: 1007
In my experience there's no better option unfortunately and you will have to perform another refresh. Your reasoning is correct.
Upvotes: 0