When creating localized web applications using ASP.net you may often come across strings which are the same on many of your interface parts. Usually you probably use the VS functionality "Generate local resources" which creates you an appropriate resx file containing the keys of your ASP.net Page or UserControl. But take for instance the simple example of a "save button" having the text "Save".Using the "generate resources" approach will lead to a situation where the text "save" appears in many different resx files. This may render it particularly difficult to make changes afterwards, i.e. when your customer suddenly wants to have the text "save content" instead of "save" alone. It would therefore make perfectly sense to have this kind of text defined globally. This can be done quite easily:
- Add the special ASP.net folder "App_GlobalResources" to your ASP.net project
You can do this by right-clicking on the project and then choosing "Add / Add ASP.NET folder / App_GlobalResources".
- Add a new resource file to the created folder
To achieve this, right-click on the App_GlobalResources folder you just created, then click "New Item" and choose "Resources file". Give it a meaningful name, i.e. "GlobalResources.resx".
- Add a new entry for your "save" text
Add a new entry to the resource file with the key "Button_Save" and the value "Save".
- Now open the ASPX code containing the definition of your button(s)
You can now set the localized text from the resource file as follows:
<asp:Button id="btnSubmit" runat="server" Text="<%$ Resources:GlobalResources, Button_Save %>"/>