Here's how I do it in Visual Studio 2013:
- For global resources, right-click Project and select
Add > Add ASP.NET Folder > App_GlobalResources . For local resources, right-click on the folder where the file you want to use the resources is located and select Add > Add ASP.NET Folder > App_LocalResources .
For labels and error messages, I prefer to use LocalResources. This practice makes the project more organized and easy to modify. Here is a link for more details.
Create resource files and name them as shown below:

It is possible to create as many App_LocalResources folders as needed, but again, the App_LocalResources folder where you put the resource files ( .resx ) should be in the same folder as the .aspx , .Master or .ascx .
Frontend.Master.resx for shortcuts and messages with the default language
Frontend.Master. pt-br .resx for Brazilian Portuguese labels and messages.
If the user changes the language of their browser to pt-BR, use pt-br.resx on the page.
Creating resource items. Name = Key, Value = Display Text

Using a local or global resource file:
<head> <title><%= GetGlobalResourceObject("Labels", "HelloWorld") %></title> </head> <body> <button type="button"> <span><%= GetLocalResourceObject("Header_NavButton_Sr") %></span> <asp:Literal runat="server" Text="<%$ resources:Header_NavButton_Sr %>"></asp:Literal> </button> <a href="index.html"><%= GetLocalResourceObject("Header_TextLogo") %></a> <asp:TextBox ID="tb1" runat="server" Text="<%$ resources:Navbar_Home %>"></asp:TextBox> </body>
GlobalResources files generate a .designer.cs file. This file generates a static class called 'Labels' if the resource file name is 'Labels.pt-br.resx', in a global namespace called Resources . The "Custom Tool" GlobalResourceProxyGenerator , which is defined in the properties of the resource file, is responsible for this, and you can access the global resources writing Resources.Labels.ResourceKey .
To make static access to LocalResources files, such as GlobalResources, you can do the following:
- Select a local resource file
- press F4 or right click and select "Properties"
- In the
Custom Tool enter 'PublicResXFileCodeGenerator' - In
Build Action select Embedded Resource - Then rebuild the application or website. Now you can see that VisualStudio generates the
.designer.cs file attached to the resource file.
How to use it?
Following the structure I create in this answer, we have a LocalResource in the MasterPages folder creating the WebFormsProject2.MasterPages.App_LocalResources namespace. If you open '.designer.cs', in this case Frontend.Master.designer.cs , in another text editor you will see that it will generate a class called Frontend_Master in the WebFormsProject2.MasterPages.App_LocalResources namespace and some static properties with the same by the name as the resource keys created in the resource file. Now you just need to create a link to this namespace and access properties such as Frontend_Master.Header_TextLogo .
Example:
<%@ Import Namespace="WebFormsProject2.MasterPages.App_LocalResources" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title><%= Frontend_Master.Header_TextLogo %></title> </head> <body>...</body>
source share