How to handle culture in asp.net
How to handle culture in asp.net pages
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Sep 1, 2009, 9:39 PM EDT
You can use the culture setting in web.config like this.
xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
-- GLOBALIZATION
This section sets the globalization settings of the application.
Use culture="en-US" for US
Use culture="en-GB" forUK
Use culture="en-AU" for AUS
-->
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-GB"
/>
system.web>
configuration>
Now in the pagebehind you can refer it like below
// To get Currency Symbol and Date Format according to the Culture settings
CultureInfo ci = CultureInfo.CurrentCulture;
Session["g_CurrencySymbol"] = ci.NumberFormat.CurrencySymbol.ToString();
Session["g_CountrySetting"] = ci.Name;
if (ci.DateTimeFormat.ShortDatePattern.ToString() == "M/d/yyyy") //US Format
{
Session["g_DateFormat"] = "MM/dd/yyyy";
}
else if (ci.DateTimeFormat.ShortDatePattern.ToString() == "d/MM/yyyy") //Australian Format
{
Session["g_DateFormat"] = "dd/MM/yyyy";
}
else
{
Session["g_DateFormat"] = ci.DateTimeFormat.ShortDatePattern.ToString();
}
Kirtan PatelRank #292 · 8.6K reputationPosted Sep 1, 2009, 7:53 AM EDT
you can handle Cultures By their name
see following code
dont forget to mark "Do you like answer" if answer helped you please :)
using System.Threading;
protected void Page_Load(object sender, EventArgs e)
{
string CurrentCulture = Thread.CurrentThread.CurrentCulture.EnglishName;
if (CurrentCulture == "English (United States)")
{
//do Somthing
}
}
Master BillaRank #2,229 · 630 reputationPosted Sep 2, 2009, 1:38 AM EDT
To this you need work on this style
http://msdn.microsoft.com/en-us/library/bz9tc508.aspx
thank you
Raghavendra Byahatti5 reputationPosted Sep 2, 2009, 7:07 AM EDT