Saturday, August 18, 2012

Setting Culture in ASP.NET

Difference between Culture and UICulture


Culture defines culture dependent objects like currency, date, currency and number formatting.  This can only defined using a specific culture (ex: en-GB not en)

UICulture defines which resources (local and global) will be loaded for this page.  Both neutral and specific cultures.

Setting Culture dynamically at runtime


Culture and UICulture need to be set in the InitializeCulture event


protected override void InitializeCulture()
{
if (Request.Form["DropDownList1"] != null)
{
//can be neutral i.e. en or en-GB
UICulture = Request.Form["DropDownList1"];
//requires a specific culture ex: de-DE
Culture = Request.Form["DropDownList1"];
}
base.InitializeCulture();
}


2 comments:

  1. It seems like CurrentUICulture in ASP.NET Development is something you would set before you fill the whole system, but CurrentCulture you will use as a reference during the system everytime you deal with date or something in that category.

    ReplyDelete
  2. CurrentUICulture is changed to tell the program which resource files to select when loading the form/page. So you would create the resource files in advance for different culture displays (translated text, right-to-left, etc.) and then within the code have it pick which one to use. ASP.NET Application Developers

    ReplyDelete