

Navigator : Home > Tutorials > Controls Tutorials > ...
A sample to show globalization in ASP.NET 2.0 and VB
The System.Globalization namespace contains classes that define culture-related information, including the language, the country/region, the calendars in use, the format patterns for dates, currency, and numbers, and the sort order for strings. These classes are useful for writing globalized (internationalized) applications. We will show you a simple sample about how to write a globalized calendar in ASP.NET 2.0 and VB.NET.
We will show three languages in the calendar, English, Chinese and Janpanse.
First, import the namespace of System.Threading.
We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
When we select one language the page will show by the selected language.
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(this.DropDownList1.SelectedValue); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(this.DropDownList1.SelectedValue); |
The front end Default.aspx page looks something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Default</title> </head> <body> <form id="form1" runat="server"> <div> <fieldset> <legend>Globalization Culture</legend>Select Language: <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem Value="en-us">English</asp:ListItem> <asp:ListItem Value="zh-CN">Chinse</asp:ListItem> <asp:ListItem Value="ja-JP">Japanese</asp:ListItem> </asp:DropDownList><br /> <br /> <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="#3366CC" BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#003399" Height="200px" Width="220px"> <SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" /> <TodayDayStyle BackColor="#99CCCC" ForeColor="White" /> <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" /> <WeekendDayStyle BackColor="#CCCCFF" /> <OtherMonthDayStyle ForeColor="#999999" /> <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" /> <DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" /> <TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" /> </asp:Calendar> </fieldset> </div> </form> </body> </html> |
The flow for the code behind page is as follows.
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!
Partial Class _Default
Inherits System.Web.UI.Page Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo(Me.DropDownList1.SelectedValue) System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo(Me.DropDownList1.SelectedValue) End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo(Me.DropDownList1.SelectedValue) System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo(Me.DropDownList1.SelectedValue) End Sub End Class |
Looking for the C#.NET 2005 Version? Click Here!