Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access to a Resource.resx from ASP.NET page?

Tags:

asp.net

I would like to access a resource-file from ASP.NET page. I have a folder named "Resources" containing the file "WebResources.resx" on the same level as the page. The name of the public class in the generated WebResources.Designer.cs is also "WebResources" My page's name is "formulargenerator.aspx". Access from code-behind works perfectly. I can access in 2 ways:

ResourceManager rm = new ResourceManager(typeof(WebResources));
string val = rm.GetString("Key");

and

string val = WebResources.Key;

But how can I access from page directly if I don't like to rename the Resource-file? I have tried to use the folder App_LocalResources - no access. Only if the resource-file is named like the page does it work. How is the syntax to access a ressource? The code below doesn't work. Must/Can I import a namespace?

<asp:Label Text="<%$Resources: WebResources, Key%>" runat="server" />

Kind regards in advance

like image 655
Rocco Hundertmark Avatar asked Jun 23 '11 09:06

Rocco Hundertmark


People also ask

How do I open resources in Resx?

Navigate resources in the editor Open a . resx file in the XML (Text) editor. Press Alt+\ or choose ReSharper | Navigate | Go to File Member… from the main menu . Alternatively, you can press Ctrl+Shift+A , start typing the command name in the popup, and then choose it there.


Video Answer


1 Answers

You might want to take look at ASP.NET Web Page Resources Overview. Local resources are specific to a concrete aspx page and use a different naming convention than global application resources. The resource tag you are using is more-likely to work if using global resources.

like image 117
Ivaylo Slavov Avatar answered Nov 12 '22 09:11

Ivaylo Slavov