0
votes

I'm having a hard time with the page cycles when using masterpages and contentpages.

My masterpage has two linkbuttons that are used to select a language (using resources). When these buttons are clicked I create Session["language"].

The goal I have is to 'translate' my masterpage after the buttons are clicked AND to translate the content page.

I've been trying all kinds of different methods (Page_Load etc) based on this url: http://msdn.microsoft.com/en-us/library/dct97kc3.aspx but it never works like it should. Usually the content page only gets translated after two clicks. I can't figure out the cycle problem between the masterpage and the content page combined with the click-events.

Any suggestions?

Thank you.

1
Please, could you post the markup of linkbuttons and code that sets Session["language"]? - Jakub Linhart

1 Answers

0
votes

I used to do this by overriding InitializeCulture method in the master page. The language code is passed via query-string:

protected override void InitializeCulture()
{
    if (!string.IsNullOrEmpty(base.Request["language"]))
    {
        System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture(base.Request["language"]);

        System.Threading.Thread.CurrentThread.CurrentCulture = culture;
        System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
    }
}

And the link will look like the following:

<a href="?language=da-DK">Vis på Dansk</a>

Don't forget to validate an input value first :-)