Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
 
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Controls - A sample to show globalization in ASP.NET 2.0 and C#
A sample to show globalization in ASP.NET 2.0 and C#


ASP.NET Controls Tutorial

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 C#.

We will show three languages in the calendar, English, Chinese and Janpanse.

First, import the namespace of System.Threading.

using System.Threading;

Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!

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);

If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.

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>

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.

The flow for the code behind page is as follows.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(this.DropDownList1.SelectedValue);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(this.DropDownList1.SelectedValue);
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(this.DropDownList1.SelectedValue);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(this.DropDownList1.SelectedValue);
}
}

Download the Full Working Version of this Project written with Visual Studio.NET C# 2005 Here!

Looking for the VB.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!





 
  Developer Resources







Server Intellect Rocks