Better Position to Set Culture RRS feed

  • Question

  • User-906454664 posted

    If we are using Master Pages with Content Page.

    Where will be the better position to set Current Culture? Content Page or Master Page.

    Any references if present.

    Tuesday, October 23, 2007 1:53 AM

All replies

  • User487807879 posted

    I would set it in Master Page, because if you ever get the need to change it, you will need to make changes in only one page (if you have more than one Master Page, than in all of them, but in any case you have less Master Pages than Content Pages). Or even better, set it in web.config like this:

    <globalization culture="hr-HR" uiCulture="auto"/>

    Tuesday, October 23, 2007 2:26 AM
  • User1642585364 posted

    You can set it in web.config as mentioned, or you'll have to do it in the content pages.  As far as I know, there isn't a way to set it in the Master page.  If you're setting it the same in all content pages, there's two ways to do it: a) you can edit each of them to have the correct culture settings, or b) you can create a class that inherits from Page, implement the InitializeCulture method for that class, and then have all your content pages inherit from your new class instead of directly from Page.  With (b), all of your pages will share the same code for setting the culture, so it'll be easier to keep them all consistent if you make later changes.

    Tuesday, October 23, 2007 12:23 PM
  • User487807879 posted

    As far as I know, there isn't a way to set it in the Master page.
    Yes, there is:
        protected void Page_Init(object sender, EventArgs e)
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("hr-HR");

    Tuesday, October 23, 2007 1:14 PM
  • User1642585364 posted

    I believe resources are set before the Init event is handled.  According to [url=http://msdn.microsoft.com/en-us/library/ms178472.aspx]this page[/url], culture is set in the Start event, which precedes the Init event.  If you've used that method and it works though, I may be mistaken.

    Tuesday, October 23, 2007 4:08 PM
  • User487807879 posted

    I believe resources are set before the Init event is handled.
    Yes, that's true. If he wants to use Resource files he will have to set culture in web.config or in content pages. But if he wants to change culture for a reason of changing page's currency or calendar than he can set it in Master Page Init event.

    Wednesday, October 24, 2007 3:27 AM