Last post Jan 30, 2008 07:45 AM by florinlabou
Jan 30, 2008 02:35 AM|raybiez|LINK
Is it possible to access the local resources (App_LocalResources) of a page from another?
A scenario: The local resource file stores a string of xml data that you'd like to fetch using an AJAX call & HTTP handler (ashx).
localization aceess crosspage
Give credit where it is due, mark a post as an answer if it helped you.
Jan 30, 2008 07:45 AM|florinlabou|LINK
ASP.NET divides resources in local and global resources. They can be accessed programmatically using ControlTemple .GetLocalResourceObject() and .GetGlobalResourceObject() methods. Although, when you are using global resources defined in App_GlobalResources
you can access them via a strongly type class available in the Resources namespace and that gets the name of the global resource file that you had defined in the project. So when you add in the App_GlobalResources a resource file with the name MyXmlData having
a string resource key XML, you can access it as Resources.MyXmlData.XML. On the other hand, the local resources are "protected", been defined as "local". You may try to 'hack' them using the resource manager. The resource manager accepts via one of the overloaded
constructors a 'baseName' parameter that represents the path to a certain resource set. For a local resource, it would be constructed out of the : "ApplicationNameSpace.App_LocalResources.PageName.aspx". This format is based on observation and not documented
in the framework (probably, it so it should not be used by programmers). Anyway you ca do something like this:
ResourceManager manager = new ResourceManager("MyWebApplicationNamespace.App_LocalResources.MyPageHavingXmlInLocalResources.aspx", System.Reflection.Assembly.GetExecutingAssembly());
string xmlFromLocalResources = manager.GetString("XML");
I would not recommend this solution. You should use global resources when you have 'resources' shared by two or more application components.