Search code examples
c#asp.netlocalizationresx

How to receive ASP.NET LocalResources resx string


I have in my ASP.NET Web Forms Application resx file localized in App_LocalResources\fr.aspx.resx with key value: hello_world.

Now I want to use it on my ASPxLabel on class Page.aspx, so I simply:

<dx:ASPxLabel ID="0" runat="server" Text="<%$ Resources:fr, hello_world %>"></dx:ASPxLabel>

but I have error: Parser Error Message: The resource object with key 'msg' was not found.

I am sure that fr.aspx.resx is publicated, but still got Parser Error. What I am doing wrong?


Solution

  • First of all check the name of your resource file. It has to follow the following naming convension

    pageName.extension.language.resx
    

    If you aspx page name Page.aspx, then the you should have resource files with the following name.(You can add resource files for further language and culture)

    Page.aspx.fr.resx
    

    Check whether you follow this convension or not.

    To you this resource in the aspx page you have to follow the convension as below

    <%$Resources:Class,ResourceID%>
    

    where Class is the name of resource file, if it is compiled as class, otherwise this can be ignored. ResourceId is the key in the resource file. In your code you are setting the resource as below. Check whether the resource file has a codebehind with the class name fr.

    Text="<%$ Resources:fr, hello_world %>">
    

    For more details you can visit the following link http://msdn.microsoft.com/en-us/library/ms227427(v=vs.90).aspx