Please help with dynamic localization!.. RRS feed

  • Question

  • User798234430 posted

    Hi, everyone!

    I was trying to make my site dynamically localizable. When user clicks some linkbutton, application should change UICulture and render the pages depending on new settings.

    I've tried to do this in PageLoad and on Init but both didn't work.

    Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo((string)Session["lang"]);

    The Session["lang"] is set to what I need, when that line executes, so that's right. And after this line CurrentThread.CurrentUICulture is set to what I need too!

    But I don't get my page rerendered using new UICulture!

    Please Help Me On This!

    PS. I'm using MasterPage, but neither master page nor child pages render the way I want.

    Thursday, August 17, 2006 3:36 AM

All replies

  • User-1936818034 posted

    Hi~ There is the faq you needed~

    Basically MasterPage is derived form UserControl but not Page class, so there is no UICulture and Culture property or InitializeCulture() for it.

    You can create Global.asax, in Application_BeginRequest(), read culture setting from where you stored it, then set Thread.CurrentThread.CurrentUICulture and Thread.CurrentThread.CurrentCulture. This is because BeginRequest is touched off before the MasterPage's lifecycle.

    Friday, August 18, 2006 1:48 AM
  • User798234430 posted

    Thanx for advice! I've solved the problem yesterday by overriding InitializeCulure() method of a page.

    And thus it occurs before masterpage is rendered, the master page localizes too. So, that's fine.

    But now I have another problem - how to intercept Click event of some asp:LinkButton control before InitializeCulture executes? Or how do I get information about what was clicked on a page in InitializeCulture() method?

    The perfect scenario for me is when I have two LinkButtons on the master page. When user clicks on 1st one - language changes to some lang1, when he(she) clicks on 2nd one - language changes to lang2.

    But InitializeCulture() is overriden in Page class. How to make that work the way I want?

    Thanx for any help!

    Friday, August 18, 2006 3:30 AM
  • User-1936818034 posted

    I'm not sure whether this will work, but you can have a try:

    Get Page.Request.Form["__EVENTTARGET"], which is supposed to be the client id of the control who triggers post back in javascript way (that is: the control isn't a submit button)

    Friday, August 18, 2006 3:39 AM