By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

CultureInfo getting hacked during page load.

P: n/a
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

Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.