Culture and UI Culture for ASP.NET Web Page Globalization  

Posted by: Quadtechindia in

In an ASP.NET Web page, you can set to two culture values, the Culture and UICulture properties. The Culture value determines the results of culture-dependent functions, such as the date, number, and currency formatting, and so on. The UICulture value determines which resources are loaded for the page.
The two culture settings do not have to have the same value. Depending on your application, it might be important to set them separately. An example is a Web auction site. The UICulture property might change for each Web browser, whereas the Culture stays constant. Therefore, prices are always displayed in the same currency and formatting.


<%@ Page Language="C#" uiculture="auto" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.Globalization" %>
script runat="server"
protected override void InitializeCulture()
{
if (Request.Form["ListBox1"] != null)
{
String selectedLanguage = Request.Form["ListBox1"];
UICulture = selectedLanguage ;
Culture = selectedLanguage ;

Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(selectedLanguage);
}
base.InitializeCulture();
}
/script
html
body
form id="form1" runat="server"
div
asp:ListBox ID="ListBox1" runat="server"
asp:ListItem Value="en-US"
Selected="True"English /asp:ListItem
asp:ListItem Value="es-MX">EspaƱol /asp:ListItem
asp:ListItem Value="de-DE">Deutsch /asp:ListItem
/asp:ListBox
br /
asp:Button ID="Button1" runat="server"
Text="Set Language"
meta:resourcekey="Button1" /
br /
asp:Label ID="Label1" runat="server"
Text=""
meta:resourcekey="Label1" /
/div
/form
/body
/html

tags cannot be posted so please add angels brackets

This entry was posted on Wednesday, November 04, 2009 and is filed under . You can leave a response and follow any responses to this entry through the Subscribe to: Post Comments (Atom) .

0 comments

Post a Comment