Date formats, culture and globalization

Discussion in 'ASP .Net' started by JimLad, Jan 22, 2010.

  1. JimLad

    JimLad Guest

    Hi,

    ASP.NET 3.5

    We are creating a 3-tier ASP.NET Web Application that needs just to
    understand dates as UK shortdate format (dd/MM/yyyy). It will only be
    used in the UK on intranet. I often come across web server and client
    machine that are incorrectly set up so I want to protect the app from
    these incorrectly set up hosts.

    I understand the safe date formats for passing through to the
    database. SQLParameters pass through a non-ambiguous format and also
    that 'yyyyMMdd' is also a safe format. So ignore the database side of
    things - I get that.

    At the moment all the bound controls are done as follows:
    <%# Bind("spouse_date_of_birth","{0:dd/MM/yyyy}") %>

    This nicely controls the inputs, but would it be better to put the
    following line in web.config:
    <globalization uiCulture="en" culture="en-GB" />
    and then specify the short date format on the page:
    <%# Bind("spouse_date_of_birth","{0:d}") %>

    Also, if we fail to convert all strings in the UI layer and then
    convert them in the BLL or DLL layer, what culture would those
    assemblies/DLLs use in the date conversion? Do they use the values
    specified in the web.config or do you specify them separately?

    One thing I am sure about is that I want to isolate the ASP.NET app
    from the culture settings on the web server and the client machine.

    Cheers,

    James
     
    JimLad, Jan 22, 2010
    #1
    1. Advertising

  2. On Jan 22, 11:52 am, JimLad <> wrote:
    > Hi,
    >
    > ASP.NET 3.5
    >
    > We are creating a 3-tier ASP.NET Web Application that needs just to
    > understand dates as UK shortdate format (dd/MM/yyyy). It will only be
    > used in the UK on intranet. I often come across web server and client
    > machine that are incorrectly set up so I want to protect the app from
    > these incorrectly set up hosts.
    >
    > I understand the safe date formats for passing through to the
    > database. SQLParameters pass through a non-ambiguous format and also
    > that 'yyyyMMdd' is also a safe format. So ignore the database side of
    > things - I get that.
    >
    > At the moment all the bound controls are done as follows:
    > <%# Bind("spouse_date_of_birth","{0:dd/MM/yyyy}") %>
    >
    > This nicely controls the inputs, but would it be better to put the
    > following line in web.config:
    > <globalization uiCulture="en" culture="en-GB" />
    > and then specify the short date format on the page:
    > <%# Bind("spouse_date_of_birth","{0:d}") %>
    >
    > Also, if we fail to convert all strings in the UI layer and then
    > convert them in the BLL or DLL layer, what culture would those
    > assemblies/DLLs use in the date conversion? Do they use the values
    > specified in the web.config or do you specify them separately?
    >
    > One thing I am sure about is that I want to isolate the ASP.NET app
    > from the culture settings on the web server and the client machine.
    >
    > Cheers,
    >
    > James


    Just use <globalization uiCulture="en-GB" culture="en-GB" /> and your
    date will be automatically shown in UK format. You will not need to
    bother about format in <%# Bind(...)%> statement. ASP.NET uses web
    application settings from the web.config file. It doesn't rely on
    client or server settings.
     
    Alexey Smirnov, Jan 22, 2010
    #2
    1. Advertising

  3. JimLad

    JimLad Guest

    On 22 Jan, 11:32, Alexey Smirnov <> wrote:
    > On Jan 22, 11:52 am, JimLad <> wrote:
    >
    >
    >
    >
    >
    > > Hi,

    >
    > > ASP.NET 3.5

    >
    > > We are creating a 3-tier ASP.NET Web Application that needs just to
    > > understand dates as UK shortdate format (dd/MM/yyyy). It will only be
    > > used in the UK on intranet. I often come across web server and client
    > > machine that are incorrectly set up so I want to protect the app from
    > > these incorrectly set up hosts.

    >
    > > I understand the safe date formats for passing through to the
    > > database. SQLParameters pass through a non-ambiguous format and also
    > > that 'yyyyMMdd' is also a safe format. So ignore the database side of
    > > things - I get that.

    >
    > > At the moment all the bound controls are done as follows:
    > > <%# Bind("spouse_date_of_birth","{0:dd/MM/yyyy}") %>

    >
    > > This nicely controls the inputs, but would it be better to put the
    > > following line in web.config:
    > > <globalization uiCulture="en" culture="en-GB" />
    > > and then specify the short date format on the page:
    > > <%# Bind("spouse_date_of_birth","{0:d}") %>

    >
    > > Also, if we fail to convert all strings in the UI layer and then
    > > convert them in the BLL or DLL layer, what culture would those
    > > assemblies/DLLs use in the date conversion? Do they use the values
    > > specified in the web.config or do you specify them separately?

    >
    > > One thing I am sure about is that I want to isolate the ASP.NET app
    > > from the culture settings on the web server and the client machine.

    >
    > > Cheers,

    >
    > > James

    >
    > Just use <globalization uiCulture="en-GB" culture="en-GB" /> and your
    > date will be automatically shown in UK format. You will not need to
    > bother about format in <%# Bind(...)%> statement. ASP.NET uses web
    > application settings from the web.config file. It doesn't rely on
    > client or server settings.- Hide quoted text -
    >
    > - Show quoted text -


    Thanks.

    How would I set the Culture and UI Culture for the BLL and DAL layers
    in separate VB.NET dlls?

    James
     
    JimLad, Jan 22, 2010
    #3
  4. JimLad

    Patrice Guest

    Hi,

    You shouldn't. The idea is to convert to a text representation at the very
    end and from a text representation as soon as possible (that is in the UI
    layer). Your BLL and DAL should deal with dates, and shouldn't have anything
    to convert. Have you run into an issue or is it a question you ask just in
    case ?

    --
    Patrice


    "JimLad" <> a écrit dans le message de
    news:...
    On 22 Jan, 11:32, Alexey Smirnov <> wrote:
    > On Jan 22, 11:52 am, JimLad <> wrote:
    >
    >
    >
    >
    >
    > > Hi,

    >
    > > ASP.NET 3.5

    >
    > > We are creating a 3-tier ASP.NET Web Application that needs just to
    > > understand dates as UK shortdate format (dd/MM/yyyy). It will only be
    > > used in the UK on intranet. I often come across web server and client
    > > machine that are incorrectly set up so I want to protect the app from
    > > these incorrectly set up hosts.

    >
    > > I understand the safe date formats for passing through to the
    > > database. SQLParameters pass through a non-ambiguous format and also
    > > that 'yyyyMMdd' is also a safe format. So ignore the database side of
    > > things - I get that.

    >
    > > At the moment all the bound controls are done as follows:
    > > <%# Bind("spouse_date_of_birth","{0:dd/MM/yyyy}") %>

    >
    > > This nicely controls the inputs, but would it be better to put the
    > > following line in web.config:
    > > <globalization uiCulture="en" culture="en-GB" />
    > > and then specify the short date format on the page:
    > > <%# Bind("spouse_date_of_birth","{0:d}") %>

    >
    > > Also, if we fail to convert all strings in the UI layer and then
    > > convert them in the BLL or DLL layer, what culture would those
    > > assemblies/DLLs use in the date conversion? Do they use the values
    > > specified in the web.config or do you specify them separately?

    >
    > > One thing I am sure about is that I want to isolate the ASP.NET app
    > > from the culture settings on the web server and the client machine.

    >
    > > Cheers,

    >
    > > James

    >
    > Just use <globalization uiCulture="en-GB" culture="en-GB" /> and your
    > date will be automatically shown in UK format. You will not need to
    > bother about format in <%# Bind(...)%> statement. ASP.NET uses web
    > application settings from the web.config file. It doesn't rely on
    > client or server settings.- Hide quoted text -
    >
    > - Show quoted text -


    Thanks.

    How would I set the Culture and UI Culture for the BLL and DAL layers
    in separate VB.NET dlls?

    James
     
    Patrice, Jan 22, 2010
    #4
  5. On Jan 22, 7:24 pm, JimLad <> wrote:
    > On 22 Jan, 11:32, Alexey Smirnov <> wrote:
    >
    >
    >
    >
    >
    > > On Jan 22, 11:52 am, JimLad <> wrote:

    >
    > > > Hi,

    >
    > > > ASP.NET 3.5

    >
    > > > We are creating a 3-tier ASP.NET Web Application that needs just to
    > > > understand dates as UK shortdate format (dd/MM/yyyy). It will only be
    > > > used in the UK on intranet. I often come across web server and client
    > > > machine that are incorrectly set up so I want to protect the app from
    > > > these incorrectly set up hosts.

    >
    > > > I understand the safe date formats for passing through to the
    > > > database. SQLParameters pass through a non-ambiguous format and also
    > > > that 'yyyyMMdd' is also a safe format. So ignore the database side of
    > > > things - I get that.

    >
    > > > At the moment all the bound controls are done as follows:
    > > > <%# Bind("spouse_date_of_birth","{0:dd/MM/yyyy}") %>

    >
    > > > This nicely controls the inputs, but would it be better to put the
    > > > following line in web.config:
    > > > <globalization uiCulture="en" culture="en-GB" />
    > > > and then specify the short date format on the page:
    > > > <%# Bind("spouse_date_of_birth","{0:d}") %>

    >
    > > > Also, if we fail to convert all strings in the UI layer and then
    > > > convert them in the BLL or DLL layer, what culture would those
    > > > assemblies/DLLs use in the date conversion? Do they use the values
    > > > specified in the web.config or do you specify them separately?

    >
    > > > One thing I am sure about is that I want to isolate the ASP.NET app
    > > > from the culture settings on the web server and the client machine.

    >
    > > > Cheers,

    >
    > > > James

    >
    > > Just use <globalization uiCulture="en-GB" culture="en-GB" /> and your
    > > date will be automatically shown in UK format. You will not need to
    > > bother about format in <%# Bind(...)%> statement. ASP.NET uses web
    > > application settings from the web.config file. It doesn't rely on
    > > client or server settings.- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > Thanks.
    >
    > How would I set the Culture and UI Culture for the BLL and DAL layers
    > in separate VB.NET dlls?
    >
    > James


    CultureInfo.CurrentCulture

    If you use dates you normally don't need it. If any string comparisons
    must be done, either use current culture or a culture-invariant string
    comparison.

    CultureInfo.CurrentCulture
    CultureInfo.InvariantCulture

    More about CultureInfo
    http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx

    Hope this helps
     
    Alexey Smirnov, Jan 24, 2010
    #5
  6. JimLad

    JimLad Guest

    On 24 Jan, 10:39, Alexey Smirnov <> wrote:
    > On Jan 22, 7:24 pm, JimLad <> wrote:
    >
    >
    >
    >
    >
    > > On 22 Jan, 11:32, Alexey Smirnov <> wrote:

    >
    > > > On Jan 22, 11:52 am, JimLad <> wrote:

    >
    > > > > Hi,

    >
    > > > > ASP.NET 3.5

    >
    > > > > We are creating a 3-tier ASP.NET Web Application that needs just to
    > > > > understand dates as UK shortdate format (dd/MM/yyyy). It will only be
    > > > > used in the UK on intranet. I often come across web server and client
    > > > > machine that are incorrectly set up so I want to protect the app from
    > > > > these incorrectly set up hosts.

    >
    > > > > I understand the safe date formats for passing through to the
    > > > > database. SQLParameters pass through a non-ambiguous format and also
    > > > > that 'yyyyMMdd' is also a safe format. So ignore the database side of
    > > > > things - I get that.

    >
    > > > > At the moment all the bound controls are done as follows:
    > > > > <%# Bind("spouse_date_of_birth","{0:dd/MM/yyyy}") %>

    >
    > > > > This nicely controls the inputs, but would it be better to put the
    > > > > following line in web.config:
    > > > > <globalization uiCulture="en" culture="en-GB" />
    > > > > and then specify the short date format on the page:
    > > > > <%# Bind("spouse_date_of_birth","{0:d}") %>

    >
    > > > > Also, if we fail to convert all strings in the UI layer and then
    > > > > convert them in the BLL or DLL layer, what culture would those
    > > > > assemblies/DLLs use in the date conversion? Do they use the values
    > > > > specified in the web.config or do you specify them separately?

    >
    > > > > One thing I am sure about is that I want to isolate the ASP.NET app
    > > > > from the culture settings on the web server and the client machine.

    >
    > > > > Cheers,

    >
    > > > > James

    >
    > > > Just use <globalization uiCulture="en-GB" culture="en-GB" /> and your
    > > > date will be automatically shown in UK format. You will not need to
    > > > bother about format in <%# Bind(...)%> statement. ASP.NET uses web
    > > > application settings from the web.config file. It doesn't rely on
    > > > client or server settings.- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > Thanks.

    >
    > > How would I set the Culture and UI Culture for the BLL and DAL layers
    > > in separate VB.NET dlls?

    >
    > > James

    >
    > CultureInfo.CurrentCulture
    >
    > If you use dates you normally don't need it. If any string comparisons
    > must be done, either use current culture or a culture-invariant string
    > comparison.
    >
    > CultureInfo.CurrentCulture
    > CultureInfo.InvariantCulture
    >
    > More about CultureInfohttp://msdn.microsoft.com/en-us/library/system.globalization.culturei...
    >
    > Hope this helps- Hide quoted text -
    >
    > - Show quoted text -


    Thanks. That's what I thought. However I've recently been stuggling
    with BLL Validation and when and where it should occur.

    I have a Gridview using an ObjectDataSource. This is a standard thing
    that I'll be doing on loads of pages and I will be creating a template
    for this.

    So obviously I can validate in the Gridview_Updating event. However,
    nothing is typed at this point so I would have to type everything
    manually. Things are typed in ObjectDataSource_Updating, but by then
    I've lost the e.cancel function and would have to raise an exception
    to cancel.
    Returning to Gridview_Updating I can pass the typed values I need
    individually or I can pass the IOrderDictionary of values, newvalues
    or keys. However these are untyped and I would have to them type them
    in the BLL layer so I've rejected this option.

    Or I can Validate in the BLL layer in the Update function. I have a
    Generic List of validation failures to return and I also want to keep
    the entered values on the page, not refresh the page if there are
    validation problems. The only way to prevent the page from refreshing
    seems to be to return an exception to GridView_Updated. I could create
    a new Exception which contains the Validation Error Generic List. But
    I have always thought that Exceptions should not be raised for
    standard functionality like this?

    Basically I want to limit bespoke validation functionality to the BLL
    layer and not have to do manual typing on the UI layer. But I can't
    seem to find a way of doing that without raising exceptions.

    Any advice would be very welcome. If these are the only 2 options,
    which should I do? I realise it would take very little effort to type
    values manually on the UI side for each page, but I always like to
    standardise code where possible.

    James
     
    JimLad, Jan 25, 2010
    #6
  7. JimLad

    JimLad Guest

    On 25 Jan, 10:54, JimLad <> wrote:
    > On 24 Jan, 10:39, Alexey Smirnov <> wrote:
    >
    >
    >
    >
    >
    > > On Jan 22, 7:24 pm, JimLad <> wrote:

    >
    > > > On 22 Jan, 11:32, Alexey Smirnov <> wrote:

    >
    > > > > On Jan 22, 11:52 am, JimLad <> wrote:

    >
    > > > > > Hi,

    >
    > > > > > ASP.NET 3.5

    >
    > > > > > We are creating a 3-tier ASP.NET Web Application that needs just to
    > > > > > understand dates as UK shortdate format (dd/MM/yyyy). It will only be
    > > > > > used in the UK on intranet. I often come across web server and client
    > > > > > machine that are incorrectly set up so I want to protect the app from
    > > > > > these incorrectly set up hosts.

    >
    > > > > > I understand the safe date formats for passing through to the
    > > > > > database. SQLParameters pass through a non-ambiguous format and also
    > > > > > that 'yyyyMMdd' is also a safe format. So ignore the database side of
    > > > > > things - I get that.

    >
    > > > > > At the moment all the bound controls are done as follows:
    > > > > > <%# Bind("spouse_date_of_birth","{0:dd/MM/yyyy}") %>

    >
    > > > > > This nicely controls the inputs, but would it be better to put the
    > > > > > following line in web.config:
    > > > > > <globalization uiCulture="en" culture="en-GB" />
    > > > > > and then specify the short date format on the page:
    > > > > > <%# Bind("spouse_date_of_birth","{0:d}") %>

    >
    > > > > > Also, if we fail to convert all strings in the UI layer and then
    > > > > > convert them in the BLL or DLL layer, what culture would those
    > > > > > assemblies/DLLs use in the date conversion? Do they use the values
    > > > > > specified in the web.config or do you specify them separately?

    >
    > > > > > One thing I am sure about is that I want to isolate the ASP.NET app
    > > > > > from the culture settings on the web server and the client machine.

    >
    > > > > > Cheers,

    >
    > > > > > James

    >
    > > > > Just use <globalization uiCulture="en-GB" culture="en-GB" /> and your
    > > > > date will be automatically shown in UK format. You will not need to
    > > > > bother about format in <%# Bind(...)%> statement. ASP.NET uses web
    > > > > application settings from the web.config file. It doesn't rely on
    > > > > client or server settings.- Hide quoted text -

    >
    > > > > - Show quoted text -

    >
    > > > Thanks.

    >
    > > > How would I set the Culture and UI Culture for the BLL and DAL layers
    > > > in separate VB.NET dlls?

    >
    > > > James

    >
    > > CultureInfo.CurrentCulture

    >
    > > If you use dates you normally don't need it. If any string comparisons
    > > must be done, either use current culture or a culture-invariant string
    > > comparison.

    >
    > > CultureInfo.CurrentCulture
    > > CultureInfo.InvariantCulture

    >
    > > More about CultureInfohttp://msdn.microsoft.com/en-us/library/system.globalization.culturei...

    >
    > > Hope this helps- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > Thanks. That's what I thought. However I've recently been stuggling
    > with BLL Validation and when and where it should occur.
    >
    > I have a Gridview using an ObjectDataSource. This is a standard thing
    > that I'll be doing on loads of pages and I will be creating a template
    > for this.
    >
    > So obviously I can validate in the Gridview_Updating event. However,
    > nothing is typed at this point so I would have to type everything
    > manually. Things are typed in ObjectDataSource_Updating, but by then
    > I've lost the e.cancel function and would have to raise an exception
    > to cancel.
    > Returning to Gridview_Updating I can pass the typed values I need
    > individually or I can pass the IOrderDictionary of values, newvalues
    > or keys. However these are untyped and I would have to them type them
    > in the BLL layer so I've rejected this option.
    >
    > Or I can Validate in the BLL layer in the Update function. I have a
    > Generic List of validation failures to return and I also want to keep
    > the entered values on the page, not refresh the page if there are
    > validation problems. The only way to prevent the page from refreshing
    > seems to be to return an exception to GridView_Updated. I could create
    > a new Exception which contains the Validation Error Generic List. But
    > I have always thought that Exceptions should not be raised for
    > standard functionality like this?
    >
    > Basically I want to limit bespoke validation functionality to the BLL
    > layer and not have to do manual typing on the UI layer. But I can't
    > seem to find a way of doing that without raising exceptions.
    >
    > Any advice would be very welcome. If these are the only 2 options,
    > which should I do? I realise it would take very little effort to type
    > values manually on the UI side for each page, but I always like to
    > standardise code where possible.
    >
    > James- Hide quoted text -
    >
    > - Show quoted text -


    I am reposting this as a new topic.
    James
     
    JimLad, Jan 26, 2010
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dejan Vesic
    Replies:
    1
    Views:
    675
    Chee Seong Ong
    Jul 3, 2003
  2. Martin Eyles

    Date Formats of Date in Database

    Martin Eyles, Mar 28, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    1,759
    Martin Eyles
    Mar 29, 2006
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,285
    Michael Borgwardt
    May 30, 2004
  4. Replies:
    2
    Views:
    1,733
    Juan T. Llibre
    Aug 13, 2006
  5. Aparna
    Replies:
    2
    Views:
    550
    Martin Gregorie
    Jun 14, 2007
Loading...

Share This Page