I want to use strings from my resx-files in my application pages. How can I refer to my resource file?

<h2><%$Resources:MyProject,Test_String_Heading%></h2> results in page crash.


I don't think you can reference it statically like that. Try this instead:

<h2><asp:Literal runat="server" ID="Literal1" Text="<%$Resources:MyProject,Test_String_Heading%>"></asp:Literal></h2>

EDIT: it's $Resources versus &Resources. Thanks for picking that up Bojan!

UPDATE: As noted below the $Resources method of referencing a resource is for global resources. The following should work for resources associated with your solution (...no manual copy of resource files required).


All you have to do to make this work is ensure that your resx has its Access Modifier set to Public and use the fully qualified resource name (i.e. namespace.class.resourceid).

  • Correct syntax is to use "$" instead of "&". Hence: <h2><asp:Literal runat="server" ID="Literal1" Text="<%$Resources:MyProject,Test_String_Heading%>"></asp:Literal></h2>
    – bojan
    Jul 26 '11 at 13:44
  • When I do so, I get an error: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Resources.MyProject.resources" was correctly embedded or linked into assembly "App_GlobalResources" at compile time, or that all the satellite assemblies required are loadable and fully signed. Jul 26 '11 at 14:24
  • Here is a tip how to solve it manually (by copiing resx file to iis virtual dir). But isn't there a way to do it automatically while deploying? Jul 26 '11 at 14:33
  • Without seeing the code/project it's hard to say exactly what the problem is. Common issues are namespace mismatches and/or the resoruce file is set to "no code generation".
    – Rob D'Oria
    Jul 26 '11 at 14:35
  • You have to copy it to <iis virtual directory>\App_GlobalResources manually or with a timer job. Infowise and jonleon.blogspot.com provide a solution for that. But you can't replace the mapped resources folder with it. Jul 26 '11 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.