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 Janpanese.
First, import the namespace of System.Threading.
We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.
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);
|
We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect's help, we were able to avoid any headaches!
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>
|
If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!
The flow for the code behind page is as follows.
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
|
Download the Full Working Version of this Project written with Visual Studio.NET VB.NET 2005 Here!
Looking for the C#.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!