Changing the active culture

Chanikya
Posted by Chanikya under ASP.NET category on | Points: 40 | Views : 1229
Changing the active culture



Both Culture and UICulture is automatically set based on the browser settings of your visitor. Try running the following page:


Culture.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Culture.aspx.cs" Inherits="Culture" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Response.Write("Your current culture: " + System.Globalization.CultureInfo.CurrentCulture.DisplayName); %>
</div>
</form>
</body>
</html>



Culture.aspx.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Culture : System.Web.UI.Page
{
protected override void InitializeCulture()
{
Page.Culture = "en-GB";
Page.UICulture = "en-GB";
}

protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Page.Culture);
}
}




Now, access your browsers language settings:

Internet Explorer: Click the Tools button, select Internet Options , then click the Languages button.

Firefox: Click the Tools menu, select Options , select the Content tab and then click the Choose button in the Languages group.

Add another language, and then move it to the top of the list. Close the dialog and reload the page (F5). You will now see the name of the culture matching your newly selected language.




http://facebook.com/chanikya.chowdary

http://labs.google.co.in/smschannels/subscribe/My-Heart2U

http://smsgupshup.com/groups/friends4ever66

Comments or Responses

Login to post response