use CompareValidator to validate date format

Discussion in 'ASP .Net' started by Neo, Jun 25, 2004.

  1. Neo

    Neo Guest

    I use CompareValidator to validate a date. But CompareValidator can only one
    date format at one time. if the dateorder is "mdy", date format can only be
    mdy even if date format is ymd. But users of a web application may be
    around the world and since database can accept many date format, so are
    there any ways to let CompareValidator accept many data formats at one
    time?

    Thanks
     
    Neo, Jun 25, 2004
    #1
    1. Advertising

  2. Neo

    Peter Blum Guest

    The page sent to the browser only needs to handle the one date format of the
    user. Your task is to identify the format of the user who is requesting the
    page. Once done, you set
    System.Threading.Thread.CurrentThread.CurrentUICulture =
    System.Globalization.CultureInfo.CreateSpecificCulture("[the Culture Name]")

    Please see the .net documentation for the CultureInfo class to understand
    about Culture Names.

    Here are some ways to identify the user's culture:
    1. Have the user pick their culture as they enter the site and keep that
    information in the Session
    2. If the user logs in, keep their culture with their login data
    3. The browser passes a list of culture names in Request.UserLanguages. See
    the .net docs for that property. Be aware that often UserLanguages is an
    empty collection and you need to provide a default.

    There is one more way to do this: Show the format you want right on the
    page.

    --- Peter Blum
    www.PeterBlum.com
    Email:
    Creator of "Professional Validation And More" at
    http://www.peterblum.com/vam/home.aspx
    and "Peter's Date Package" at
    http://www.peterblum.com/datecontrols/home.aspx

    "Neo" <> wrote in message
    news:ewDr%...
    > I use CompareValidator to validate a date. But CompareValidator can only

    one
    > date format at one time. if the dateorder is "mdy", date format can only

    be
    > mdy even if date format is ymd. But users of a web application may be
    > around the world and since database can accept many date format, so are
    > there any ways to let CompareValidator accept many data formats at one
    > time?
    >
    > Thanks
    >
    >
     
    Peter Blum, Jun 25, 2004
    #2
    1. Advertising

  3. Neo

    adamyang

    Joined:
    Nov 28, 2007
    Messages:
    1
    In the Session_Start method of your global.asax

    put
    Code:
     
            System.Threading.Thread.CurrentThread.CurrentUICulture =
                System.Globalization.CultureInfo.CreateSpecificCulture("your culture code");
    
    example
    Code:
     
       void Session_Start(object sender, EventArgs e) 
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture =
                System.Globalization.CultureInfo.CreateSpecificCulture("en-NZ");
    
        }
    
     
    adamyang, Nov 28, 2007
    #3
    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. =?Utf-8?B?Q3liZXJMb3R1cw==?=

    Does CompareValidator work for the date in dd-mmm-yyyy format?

    =?Utf-8?B?Q3liZXJMb3R1cw==?=, Jun 10, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    15,825
    Peter Blum
    Jun 10, 2005
  2. cashdeskmac

    CompareValidator won't validate

    cashdeskmac, Nov 21, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    354
    cashdeskmac
    Nov 26, 2007
  3. Dave
    Replies:
    1
    Views:
    588
    bruce barker
    Mar 25, 2008
  4. VancouverMike
    Replies:
    0
    Views:
    604
    VancouverMike
    Apr 11, 2008
  5. Jay Pangmi
    Replies:
    4
    Views:
    666
    Suraj Kurapati
    Aug 25, 2008
Loading...

Share This Page