Reputation: 481
I have a DropDown Menu "DDLanguage" where the user choses the Language for the application, and this ovveride methode thats sets the according Culture. So far so good.
protected override void InitializeCulture()
{
String language = Request.Form["DDLanguage"];
if (!string.IsNullOrEmpty(language))
{
if (language == "auto")
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(HttpContext.Current.Request.UserLanguages[0].Trim());
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(HttpContext.Current.Request.UserLanguages[0].Trim());
}
else
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(language);
}
}
}
I then introduced a Querystring Parameter to pass the selected Language to the page on one of the required reload events. This causes some conflict between the language being given by the query string on one side and the dropdown on the other. I want the Querystring to be mandatory only for the first pageload, but afterwards it should not be considered anymore, as it is then overruled by the choice of the DropDown Menu.
The code I wrote to handle this was:
String language = Request.Form["DDLanguage"];
String languageChanged = Request.Form["LabelLanguage"];
if (!string.IsNullOrEmpty(Request.QueryString["Lang"]) && string.IsNullOrEmpty(languageChanged))
{
language = Request.QueryString["Lang"];
}
where LabelLanguage stores the selection of the DropDown Menu and is empty until a first choice is made.
Unfortunately that doesn't work and the culture is only set by the query Parameter. Any suggestion is appeciated. Thanks, Martin
Upvotes: 0
Views: 58
Reputation: 481
The logic that I applied was correct, but
String languageChanged = Request.Form["LabelLanguage"];
would not return a value. I now know that I can't process data of a Label, as it is not rendered to a html element containing a value. Instead I use a asp:HiddenField that is rendered in a way its value can be requested by that command.
Upvotes: 0