Take the 2-minute tour ×

My current solution consists of several Class Libraries and a Website. I'm in the process of globalizing the application and I realized that my resources need to be accessed by all the projects not just the website so placing my resources in the App_GlobalResources folder didn't work.

I added my resources to one my class Libraries and now I'm trying to figure out what the best way of accessing the resources are from my markup. When my resources were in the App_GlobalResources folder I was able to access them by using an expression such as this:

<$ Resources: MyApp.Name %>  for server controls


<%=Resources.MyApp.Name %> for plain text

What's the best way of accessing my Resources from my website aspx files now that they are in a Class Library DLL?

Thanks for your help!

share|improve this question
Perhaps set the ASPX's project to be dependent upon the Class Library Project. If you are simply including the DLL and not the Class Library Project itself, make sure you have a reference to the DLL in your project. –  George W Bush Feb 27 '10 at 6:33
add comment

2 Answers

up vote 3 down vote accepted

I found a great article which discusses Extending the Resource-Provider Model. It allows for the use of expressions to access external resources:

The syntax for a $Resources expression for the default provider model (explicit global resources) is the following.

<%$ Resources: [resourceType], [resourceKey] %>

The same expression can be used to access external resources when the ExternalResourceProviderFactory is configured, with the following syntax change.

<%$ Resources: [assemblyName]|[resourceType], [resourceKey] %>

For example, to retrieve a resource from the CommonResources.dll assembly, from the global resource type "CommonTerms", you would use the following explicit expression.

<asp:Label ID="labGlobalResource" runat="server" Text="<%$ Resources:CommonResources|CommonTerms, Hello %>" ></asp:Label>
share|improve this answer
add comment

I use an Util class library which apart from a host of other useful classes and functions contains an i18n class with a Public Shared Function that returns the value (string) of a resource in a resource file based on its name and LCID. I add a reference to that dll in my web projects and where ever needed, say in a code-behind file for a label I write : MyLabel.Text = i18n.GetResourceString("MyStringName",1033) You can find a more detailed description of the method I use here I trust that with the details provided there you can adopt or adapt my solution.

share|improve this answer
That works for the code-behind but what about the markup? –  mga911 Mar 4 '10 at 18:20
I'm sorry, but I don't understand. You could write in the mark-up : <asp:Label id="MyLabel" runat="server" Text='<%# Util.i18n.GetResourceString("MyStringName", 1033) %>' /> Assuming the assembly is called Util.dll. But you still would have to call MyLabel.DataBind from the code-behind for it to work. So you might as well write MyLabel.Text = i18n.GetResourceString("MyStringName",1033) directly in the code-behind onload. –  esjr Mar 5 '10 at 4:37
By the way, this would work without code-behind : <div> <%=Util.i18n.GetResourceString("NameText", 1033)%> </div> Again assuming, the assembly is Util.dll, referenced in your project and i18n's GetResourceString is a Public Shared Function. –  esjr Mar 6 '10 at 6:41
add comment

Your Answer


