Culture / Damn US! ASP.Net 2.0

R

Rob Meade

Hi all,

Ok - firstly - I love the states, would love to go there again soon - the
one thing I dont want though are my dates all muddled up on my web page ;o)

My laptop is configured correctly for UK/English, for everything, keyboard,
regional, language - SQL is set up as such also, the only thing thats
changed recently was the installation of .Net 2.0. When I run my
application a date that is being pulled out of my database keeps appearing
as mm/dd/yyyy (plus the time bits on the end)...

I've tried adding :

Culture = "en-GB"

in my base class...no difference..

I've tried adding:

Culture = "en-GB"

in the @page reference at the top of the html

I've even thrown a CONVERT around the date field in the stored procedure
used to grab it out of the database...

CONVERT(datetime, FirstDateTime, 113) AS FirstDateTime

and STILL it appears as mm/dd/yyyy (and the time bits)..

Can anyone advise me as to whether there is an overriding setting perhaps in
VS2005, or some such which might be causing this....obviously I could spend
the evening writing code to change it all around but I would have thought
that at least ONE of hte above methods might have resolved the problem!

Any help would be really appreciated.

Thanks

Rob
 
H

hoague

Rob, please consider that an accent tax - viewing our date format is
what you Brits owe us for coming over and getting women to notice you
simply by talking.
 
R

Rob Meade

Rob, please consider that an accent tax - viewing our date format is
what you Brits owe us for coming over and getting women to notice you
simply by talking.

ROTFL!

Thats good - thats really good :eek:)

Oh, and if you'd seen me, you'd know that no matter how I spoke - it would
make no difference :eek:)

Oh, and didn't we give you your language in the first place anyway?? :eek:D

Rob
(awaiting the flaming to commence...)
 
J

Juan T. Llibre

In your web.config, include :

<globalization
culture="en-GB"
uiCulture="en-GB"
/>
 
R

Rob Meade

...
In your web.config, include :

<globalization
culture="en-GB"
uiCulture="en-GB"
/>

Hi Juan,

Thanks for that, I added it within the <system.web> section - I trust that's
correct....if so - it hasn't made any difference - if I run the app in debug
mode I can hover over the variables and they are still in US format... :eek:/

Rob
 
B

Bruce Barker

when you hover in the debugger, you are using the debuggers culture
settings. its unmanaged code, so it should follow the settings for all your
windows apps.

-- bruce (sqlwork.com)
 
R

Rob Meade

...
when you hover in the debugger, you are using the debuggers culture
settings. its unmanaged code, so it should follow the settings for all
your windows apps.

Hi Bruce,

Thanks for that, handy to know the differences - it still wrong though, on
the page, and in the app...

I've even gone through regedit and checked all the "international" values
and they are all country code 44.....

:eek:(

Rob
 
H

hoague

Rob you certainly gave us something to work with, to absorb or filter
as appropriate. The linguistic equivalent of British meals - you may
have offered bacon pudding, flummery and eel pie, but seeing something
in sore need of improvement, we added a few touches (above-ground
vegetables and fruits come to mind) to enhance the original.

did you try setting the culture for the thread in the postback of the
page?

System.Threading.Thread.CurrentThread.CurrentCulture = new
System.Globalization.CultureInfo("en-GB");
System.Threading.Thread.CurrentThread.CurrentUICulture = new
System.Globalization.CultureInfo("en-GB");
 
J

Juan T. Llibre

re:
I added it within the <system.web> section - I trust that's correct

It is.

re:
if so - it hasn't made any difference

That's the first time I hear that doesn't make a difference
regarding SQL server data being formatted for display in
cultures other than the SQL server default culture format.

re:
if I run the app in debug mode I can hover over the variables and they are still in US
format

What happens if you run the app in your browser,
and not in the VS.NET IDE ?
 
R

Rob Meade

Rob you certainly gave us something to work with, to absorb or filter
as appropriate. The linguistic equivalent of British meals - you may
have offered bacon pudding, flummery and eel pie, but seeing something
in sore need of improvement, we added a few touches (above-ground
vegetables and fruits come to mind) to enhance the original.

ROTFL!

Ok - so what did you do to....

"colour" / "color"
"flavour" / "flavor"

you lopped stuff outta those! let me guess - you removed the unwanted chewy
bits? :eek:D
did you try setting the culture for the thread in the postback of the
page?

Nope - bit new to me this...
System.Threading.Thread.CurrentThread.CurrentCulture = new
System.Globalization.CultureInfo("en-GB");
System.Threading.Thread.CurrentThread.CurrentUICulture = new
System.Globalization.CultureInfo("en-GB");

Have added that - no difference to the dates on the page....

?? :eek:(

Rob
 
R

Rob Meade

...
That's the first time I hear that doesn't make a difference
regarding SQL server data being formatted for display in
cultures other than the SQL server default culture format.

That dont sound so good :(
What happens if you run the app in your browser,
and not in the VS.NET IDE ?

I was :eek:(

Rob

I should add that the SQL Server is not "on" the laptop, instead its on a
remote server, I've checked all the "international" settings on that too -
and they are again all country code 44's...the only slight "hint" of an
issue is that on the "Properties" of the SQL Server it says "Language:
English (United States)" - I dont seem to be able to change this anywhere,
so I'm assuming it was a setting that was incorrectly chosen (if applicable)
during the install?

That said, surely, something of all of the above suggestions and efforts
should have over ridden the date format?

The dates all "look" ok when I view them "in" sql server...but I've heard
you cant rely on that anyway...

Anything else I can check? My other apps/databases using old ASP (not .net)
all seem fine with the dates - I might have just chucked a CONVERT around
them in the stored procs but that would have been it...

Rob
 
J

Juan T. Llibre

re:
I should add that the SQL Server is not "on" the laptop, instead its on a remote server

That doesn't matter.

re:
on the "Properties" of the SQL Server it says "Language: English (United States)"

That doesn't matter IF you've set a different culture in web.config.
ASP.NET converts/formats *all* culture settings by the value specified there.

re:
That said, surely, something of all of the above suggestions and efforts should have
over ridden the date format?

That's exactly it.

It doesn't matter which format/culture the date is stored in.
ASP.NET will format the data for the culture specified in web.config
no matter which format/culture is specified anywhere else.
 
R

Rob Meade

...
It doesn't matter which format/culture the date is stored in.
ASP.NET will format the data for the culture specified in web.config
no matter which format/culture is specified anywhere else.

Here's my config file...

<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>
<connectionStrings>
</connectionStrings>
<system.web>
<globalization culture="en-GB" uiCulture="en-GB" />
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.

Visual Basic options:
Set strict="true" to disallow all data type conversions
where data loss can occur.
Set explicit="true" to force declaration of all variables.
-->
<compilation debug="true" strict="false" explicit="true"/>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
</namespaces>
</pages>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly"
defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>



That look ok? It's basically what I was given by VS2005, plus the code from
your good self...

Rob
 
R

Rob Meade

Just a thought...

Does it matter that the web.config file is at the root level, yet the code
that is playing with the dates (ie, my sqldatareader) is in a class which is
stored in a folder, in a folder in the app_Code folder?

Rob
 
M

Mark Rae

Rob, please consider that an accent tax - viewing our date format is
what you Brits owe us for coming over and getting women to notice you
simply by talking.

LOL! You don't know how true that is... I do recall a particularly athletic
redhead from Baltimore back in the early 90s... ;-)
 
J

Juan T. Llibre

re:
Does it matter that the web.config file is at the root level
Nope.

re:
yet the code that is playing with the dates (ie, my sqldatareader) is in a class which
is stored in a folder
Nope.

re:
in a folder in the app_Code folder?

Nope.

Anything which is anywhere ( in any directory ) will get compiled.

The web.config culture/UIculture settings only apply for display(rendering),
after the compiled code has already run.
 
R

Rob Meade

...
The web.config culture/UIculture settings only apply for
display(rendering),
after the compiled code has already run.

I'm not sure what the problem is then - I've also tried the small example
Philip posted in my other thread this evening entitled "Confusion:
TableRowCollection" - at the bottom of that thread Philip gives me a small
example to try - even this appears in US format!?

Rob
 
G

Guest

I would suggest that you create a new folder without any special
configurations in it and test in it.

Open your IIS manager, right-click on Default Web site, click on
New->Virtual Directory then create a directory named "test1" (Or something
similar) then copy in it the sample that I have on my website, remove the 2
lines that read:
<%@ Register TagPrefix="Societopia" tagName="PageHeader"
src="PageHeader.ascx" %>

<Societopia:pageHeader runat="server"
id="PageHeader1"></Societopia:pageHeader>

Browse the page and it will compile (Just In Time) then tell me the outcome.
 
R

Rob Meade

...
I would suggest that you create a new folder without any special
configurations in it and test in it.

Right-clicked, created a new virtual directory, pointed it to a new folder
named "test1" also. In IIS added "Run Scripts (eg ASP)", Read was already
selected.

Opened VS2005, opened website, it told me that the VD was configured for
1.1.4322 (or similar) and would I like to convert to .net 2.0 - I selected
yes - the website opened.

Added a new webform, named Default.aspx

Pasted in your code.

Moved the inline code from <script> tags and put it in the code behind page-
changed syntax to the following for VB.

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

Calendar1.SelectedDate = DateTime.Now

Label1.Text = "Today's date is <b>" +
Calendar1.SelectedDate.ToLongDateString() + "</b> (long date format), <b>" +
Calendar1.SelectedDate.ToShortDateString() + "</b> (short date format) " + "
displayed according to the browser's culture setting of: <br><b>" +
Culture.ToString() + "</b>"

End If

End Sub

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar1.SelectionChanged

Label1.Text = "The date you selected is: <b>" +
(sender.SelectedDate.ToLongDateString() + "</b> (long date format), <b>" +
((sender.SelectedDate.ToShortDateString() + "</b> (short date format) " + "
displayed according to the browser's culture setting of: <br><b>" +
Culture.ToString() + "</b>")))

End Sub

End Class


Hit Ctrl-F5 to build it (not in debug mode, thus the webconfig.file was not
amended.

Output on page was this:

Today's date is 22 November 2005 (long date format), 11/22/2005 (short date
format) displayed according to the browser's culture setting of:
English (United Kingdom)

When I selected another date - the correct date was "highlighted" on the
calendar control, and this text appeared...

The date you selected is: 02 December 2005 (long date format), 12/2/2005
(short date format) displayed according to the browser's culture setting of:
English (United Kingdom)

So month/day still around the wrong way :eek:/

Regards

Rob
 
G

Guest

Hi Rob,

From your PC Start->Control Panel->Regional and Language Options, you will
be able to view the settings you have for the selected culture. You can
click on customize to change the settings for Number, Currency, Time, and
Date display formats. This should fix the problem. Let me know of the
outcome.
 

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,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top