Globalization Example in ASP.NET using C#

Globalization Example in ASP.NET using C#


Posted in : ASP.Net Posted on : December 14, 2010 at 6:22 PM Comments : [ 0 ]

In this article we will introduce with Globalization in ASP.NET using C#.

Globalization Example in ASP.NET using C#

Globalization is the process in which you can use the multiple culture. There are two types culture values of web forms Culture and UICulture. Culture is used for function such as Date, currency. It is used for date formatting and number formatting. UICulture is used to determine which language the resources should load. These cultures don't need to have same values. In this example we use a dropdownlist, calendar and label. when you select the language form deopdownlist you will see the change in language.

Globalization.aspx (Design Page):

Globalization.aspx (source code):

<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.Master" 
AutoEventWireup="true"
CodeFile="Globlization.aspx.cs" Inherits="Globlization" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div>
<h2 style="color: Green">
Globalization in ASP.NET 4, C#
</h2>
<strong>Select Language:</strong>
<asp:DropDownList ID="language_Drp" runat="server" AutoPostBack="True" OnSelectedIndexChanged="language_Drp_SelectedIndexChanged">
<asp:ListItem Value="en-US">English</asp:ListItem>
<asp:ListItem Value="ja-JP">Japanese</asp:ListItem>
<asp:ListItem Value="zh-CN">Chinse</asp:ListItem>
<asp:ListItem Value="de-DE">Deutsch</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="Black"
Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="250px" Width="330px"
BorderStyle="Solid" CellSpacing="1" NextPrevFormat="ShortMonth">
<DayHeaderStyle ForeColor="#333333" Height="8pt" Font-Bold="True" Font-Size="8pt" />
<DayStyle BackColor="#CCCCCC" />
<NextPrevStyle Font-Size="8pt" ForeColor="White" Font-Bold="True" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TitleStyle BackColor="#333399" Font-Bold="True" Font-Size="12pt" ForeColor="White"
Height="12pt" BorderStyle="Solid" />
<TodayDayStyle BackColor="#999999" ForeColor="White" />
</asp:Calendar>
<br />
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Verdana" 
Font-Size="Small" ForeColor="#CC0000" ></asp:Label>
</div>
</asp:Content>

Globalization.aspx.cs (C# code file):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Globlization : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void language_Drp_SelectedIndexChanged(object sender, EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(this.language_Drp.SelectedValue);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(this.language_Drp.SelectedValue);
Label1.Text = System.DateTime.Now.ToString();
}
}

Output:

Download source code
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics