views:

25

answers:

1

I know I'm doing something fundamentally wrong, but I can't quite figure it out...

I have 2 resource files in my App_GlobalResources folder: Global.resx and Global.fr-CA.resx.

I have the following label on my webform:

<asp:Label ID="Label1" runat="server" Text="<%$ Resources:Global, Test %>" />

When I run the form, it displays the value correctly from Global.resx. Now, in code-behind, I want to manually change the culture to pull from my fr-CA resx file:

Page.UICulture = "fr";
Page.Culture = "fr-CA";

However, when I re-run the app it doesn't pull the value from Global.fr-CA.resx - it still pulls from Global.resx. What am I doing wrong?

Thanks!!

+1  A: 

You should override the InitializeCulture() method of your page class and set both Page.Culture and Page.UICulture to the specific culture fr-CA:

protected override void InitializeCulture()
{
    base.InitializeCulture();
    Page.Culture = Page.UICulture = "fr-CA";
}
Frédéric Hamidi
I made the change but it still does not work properly.
Mike C.
What's the neutral culture of your assembly?
Frédéric Hamidi
It's set to None.
Mike C.
So you have english strings in your `Global.resx` file? Does it help if you also set `Page.UICulture` to `fr-CA`?
Frédéric Hamidi
Blamo - that worked! I tried that before I moved it to the override InitializeCulture(). If you edit your answer I'll accept it.
Mike C.