Adopting Culture Settings in ASP.NET


In addition to using server-side settings to define the culture for your ASP.NET pages, you also have the option to define the culture with what the client has set as his or her preference in a browser instance.

When end users install Microsoft’s Internet Explorer and some of the other browsers, they have the option to select their preferred cultures in a particular order (if they have selected more than a single culture preference). To see this in action in IE, select Tools image from book Internet Options from the IE menu. On the first tab provided (General) is a Languages button at the bottom of the dialog. Select this button and you are provided with the Language Preference dialog shown in Figure 6-6.

image from book
Figure 6-6

Two cultures are selected from the list of available cultures. To add any additional cultures to the list, click the Add button and select the appropriate culture from the list. After you have selected any cultures present in the list, you can select the order in which you prefer to use them. In the case of Figure 6-6, the Finnish culture is established as the most preferred culture, whereas the U.S. version of English is selected as the second preference. A user with this setting gets the Finnish language version of the application before anything else; if a Finnish version is not available, a U.S. English version is presented instead.

After you, as the end user, make this selection, you can use the new auto feature provided in ASP.NET 2.0. Instead of specifying a distinct culture in any of the configuration files or from the @Page directive, you can also state that ASP.NET should automatically select the culture provided by the end user requesting the page. This is done using the auto keyword, as illustrated here:

  <%@ Page Language="VB" UICulture="auto" Culture="auto" %> 

With this construction in your page, the dates, calendars, and numbers appear in the preferred culture of the requester. What happens if you have translated resources in resource files (shown later in the chapter) that depend on a culture specification? Or what if you have only specific translations and therefore can’t handle every possible culture that might be returned to your ASP.NET page? In this case, you can specify the auto option with an additional fall-back option if ASP.NET cannot find the culture settings of the user (such as culture-specific resource files). This usage is illustrated in the following code:

  <%@ Page Language="VB" UICulture="auto:en-US" Culture="auto:en-US" %> 

In this case, the automatic detection is utilized, but if the culture the end user prefers is not present, then en-US is used.




Professional VB 2005 with. NET 3. 0
Professional VB 2005 with .NET 3.0 (Programmer to Programmer)
ISBN: 0470124709
EAN: 2147483647
Year: 2004
Pages: 267

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net