Search code examples
asp.netresxmultilingual

asp.net global resources error 'The resource object with key '' was not found'


I'm using asp.net global resource to try and implement a two language website, I added a simple resource in the global resource file called en-Us.resx that contains:

Password | Text
Email | Text

then implemented it to a textbox within the default page:

<asp:TextBox runat="server" ID="loginEmail" Text="<%$ Resources:en-US, Email %>" 
                            ></asp:TextBox>

but when ever I run the page on localhost I get this error:

The resource object with key '' was not found

I am using asp.net 4.0, what is the problem?


Solution

  • The format of resource files are ResourceName.culture.resx

    Create a resource file in the App_GlobalResources folder called Main.resx. This is for the default culture ( ie Invariant )

    Then create a resource file Main.en-US.resx

    This is where all the resources for en-US culture will live, and so on.

    Main.resx  
    Main.en.resx  
    Main.en-US-resx  
    Main.en-AU.resx  
    Main.fr.resx  
    Main.fr-FR.resx  
    

    etc.

    To access this from the webpage use the syntax

    <%$ Resources:Main, Email %>
    

    Don't worry around the culture, the system will work it out. It will exact match first ( en-US ), then work up to that's cultures parent ( en ), parent's parent ( Invariant ).

    Change the name of "Main" to suit your needs