Question

I have a resource file placed in the App_LocalResources folder inside the folder for a theme in App_Themes like so: \App_Themes\Theme1\App_LocalResources\Resources1.aspx.resx

How can I access the resources in this file from a web form in my project, assuming the web form is called Resources1.aspx having Theme="Theme1"?

Was it helpful?

Solution

You can use the "Resources" expression to extract values from the resource file, for instance:

<h1><%$ Resources: H1 %></h1>

Alternatively, and especially if you're in code-behind, use GetLocalResourceObject:

h1.InnerText = GetLocalResourceObject ( "H1" ).ToString ( );

EDIT: Sometimes i answer too fast; i don't think themes are localizable in that sense, however there are some workarounds. You could have theme specific items in the resource file and access them depending on current theme.

OTHER TIPS

You can access globalresources located in \App_GlobalResources\Generic.resx with;

<%= Resources.Generic.Cancel %>

Local resources reside in an App_LocalResources folder which doesn't necessarily have to be be placed in the root folder. For a localresource it would be;

<%$ Resources:Cancel%>

or

string labelCancel = GetLocalResourceObject("Cancel").ToString();

As far as placing resource files in your theme folders go; I'd keep my themes and resources separated and programmatically switch between various resources in a site master/basepage or such by making use of globalresources.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top