Hi Tom,
You're indeed almost there. A few more steps and you'll be done!
What you're trying to do is to parse the HTTP POST that you're getting, because the InitializeCulture method is called before you even get the DropDownList_Changed event.
I believe reading HTTP POST in ASP.net is a quite bad solution. A better one I'd recommend is to simply ask for your page to reload inside the DropDownList_Changed event (that is, when you get an event telling you that the user chose another language).
Just look at the code I'd recommend you place in the CodeBehind of your master page:
protected void UseEnglishAction_Click(object sender, ImageClickEventArgs e)
{
HttpContext context = HttpContext.Current;
context.Session["Language"] = new CultureInfo("en-GB");
// Re-process current page from the start
context.Server.Transfer(context.Request.Path);
}
And in your BasePage:
protected override void InitializeCulture()
{
CultureInfo preferredCulture = HttpContext.Current.Session["Language"] as CultureInfo;
if (preferredCulture != null)
{
Thread.CurrentThread.CurrentUICulture = preferredCulture;
Thread.CurrentThread.CurrentCulture = preferredCulture;
}
base.InitializeCulture();
}
That's it! The trick is to call Server.Transfer(context.Request.Path) in order to reload your page.
It works like a charm on my site...
Microsoft .net Training and Consulting
http://www.dreamdotnet.com/
