CultureInfo getting hacked during page load.

G

Guest

OS: WIndows Server 2003.
Currently logged in user is running with German(German) regional settings.

Code fragment:
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("de-DE")
string name= culture.Name; // Produces "de-DE"
string s = (3.5).ToString(culture); // produces "3.5". Should produce "3,5"
string t = (new System.DateTime()).ToString("T",culture); // produces "2/16/2004". Should produce "16.2.2004"

If the currently logged in user is running with English(US) regional settings, the problem does not occur. This problem occurs for both locally and remotely connected HHTP settings.

What seems to be happening is that the regional settings for the CultureInfo corresponging to the default locale for the currently logged on user seems to get patched with en-US NumericFormat and DateFormat settings for the duration of OnInit and OnLoad. I can understand why somebody might want to do this. Problem is, that I have a validating date control that needs to convert posted values to native DateTimes. When I try to do

System.DateTime newDate =
System.DateTime.Parse(text)

in the postback handler, it failes, because it tries to parse the strings using the current CultureInfo, which has been mysteriously patched with en-US values. I'm helpless. There doesn't appear to be a way to get CultureInfo for "de-DE" that hasn't been hacked

If the logged in users' regional settings are changed to en-US (or, in fact, anything other the de-DE), everything works fine

Page generation works fine. By the time we get around to generating HTML, the correct format strings have been patched back in again

During postback handling, even

System.DateTime.Parse(text,new System.Globalalization.CultureInfo("de-DE"))

fails, because the Culture info returned includes the patches to the format patterns.

What's annoying is that I'm running with the right CultureInfo (Name="en-US") during page construction; and I even seem to be running with the right CultureInfo (Name="de-DE") during parameter postback.

Is there a way to disable this behaviour in ASP.NET?

I've tried explicitly setting the culture in the page. Doesn't help
 
N

Natty Gur

Hi,

I got the same problem with hebrew. changing the cultute attribute in
globalization tag at the web.config solved the problems for me.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top