CultureInfo & ASP.NET

Posts   
 
    
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 14-Jan-2005 02:27:27   

I am running into some oddness with CultureInfo and the asp.net datagrid.

Basically, I have an http handler that wires up to the httpapplication.BeginRequest event. HEre is the code:


HttpApplication applicaiton = (HttpApplication)sender;
HttpContext context = applicaiton.Context;

if (context != null)
{
    // set the culture info for later processing
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(context.Request.UserLanguages[0]);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(context.Request.UserLanguages[0]);
}

I also moved the last 2 lines of code into the web user control giving me the problem. Basically in the web user control, I fetch an entity collection from the sql database (which stores the data in a culture invariant way) and I bind the collection to the asp.net grid.

For some cells the dates look right, and for some they dont. It seems like the second date cell in each row is wrong, i.e. showing the US date when it should be displaying whatever the browsers setting is. I am setting the data format string for each data column that is a date to

{0:d}

which is the short date format and should use the current threads culture.

Has anyone experienced anything like this? I get the same results on servers in both AU and the US.

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 21-Jan-2005 06:54:01   

Bummer, I was sure there was a guru out there who had seen this one. So far, I am not impressed with the touted globalization improvements in asp.net / .net fw 1.1.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39801
Joined: 17-Aug-2003
# Posted on: 21-Jan-2005 10:28:52   

It's clunky... somewhere you have to react on the language stated in the browser, but I have yet to see a site which works with that technique successfully.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 46
Joined: 07-Jan-2004
# Posted on: 21-Jan-2005 14:47:17   

Otis wrote:

It's clunky... somewhere you have to react on the language stated in the browser, but I have yet to see a site which works with that technique successfully.

take a look at the esperantus project on sourceforge.

John