This post will be about the globalization and localization techniques ASP.NET provides us. There are two types of resources which you can use in an ASP.NET page: global, which means they are accessible from all pages, and local, for each given page. First let’s see how to use global resources.
To enable them, add a special folder named App_GlobalResources. In this folder, you can insert whatever resource you’d like to use. Let’s insert a .resx file, this will be the default culture you’d use. Let’s call it GlobResx.resx. Add a key-value pair, for example HeaderText = Hello World. Now on a random .aspx page, define a Label control, and set its text property to <%$ Resources: GlobResx, HeaderText %>. Now you are done, when you run your site, you’ll see Hello World as the label’s text.
Now let’s take a further step. Create a file named GlobResx.en.resx into the App_GlobalResources folder. Add the same HeaderText entry, but now use the value: Hello for the English-speaking World! If your browser is set up to use the English culture, you’d see your label shows the new text.
Master pages are a very powerful feature to provide a consistent look and feel for your site. They also help you focus on the content of each individual page, rather than re-implementing for example the navigation of your page each time.
However, sometimes you need to access the master page from one of your content pages (the other way around makes less sense). A cool thing to do is to create strongly-typed master pages. This is achieved by only a single directive, called MasterType. It looks like this:
<% @MasterType virtualPath=”~/MasterPage.master” %>
Themes allow you to build sites with a consistent layout. You can set them up by adding an App_Themes directory for your application, and fill it up with folders. Each folder in the App_Themes directory represents a theme. You can assign them in a number of ways, in each case using the folder name to identify the theme.
There are five levels of applying themes:
- @Page Theme
- Web.config <pages Theme=””>
- Local control attributes
- @Page StyleSheetTheme
- Web.config <pages StyleSheetTheme=””>
A level at the beginning of the list overrides one at the end. So when you set a theme in the Page directive, it will override all the other style settings.