[CLOSED] Datafield set to specific cuntry default format

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Datafield set to specific cuntry default format

    Hi, I would set the date format of a datafield (in aspx ) to a specific country default that is different from the OS default?
    is it possible ?
    Thanks in advance

    es: (mm/dd/yyyy I want to set to dd/mm/yyyy)
    Last edited by Daniil; Jul 19, 2012 at 4:44 PM. Reason: [CLOSED]
  2. #2
    Hi,

    You can always set up the DateField Format property.

    Also if you would set up a current culture this way
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-ES");
    or in the Web.config, the respective format should be applied automatically.

    Setting up
    <ext:ResourceManager runat="server" Locale="client" />
    causes localization according the current browser locale.
  3. #3
    Hi Daniil,
    thanks, I just used format and it worked.
    I identified the following issue after I tried to handle the CultureInfo
    please consider the following example:

    press the button and get the date value in the text field

    1. if i set the CultureInfo to it-IT, it works
    2. if i do the same with en-Us I get the null date value

    can you run it to see to reproduce the same result?

    Click image for larger version. 

Name:	date(it-IT).png 
Views:	89 
Size:	3.2 KB 
ID:	4478Click image for larger version. 

Name:	date(en-US).png 
Views:	99 
Size:	3.3 KB 
ID:	4479
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");
            
            // System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
    
            if (!X.IsAjaxRequest)
            {
                DateField1.Value = DateTime.Now;
                string d = DateField1.Value.ToString();
            }
        }
    
        protected void getDate(object sender, DirectEventArgs e)
        {
            string d = DateField1.Value.ToString();
            txtSelDate.Text = "day " + DateField1.Value.ToString(); ;
        }
        
    </script>
    <!DOCTYPE>
    <html>
    <head id="Head1" runat="server">
        <title>Date example</title>
        <script type="text/javascript">
    
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        
        <ext:DateField ID="DateField1" FieldLabel="Date" runat="server">
        </ext:DateField>
    
        <ext:TextField ID="txtSelDate" FieldLabel="Date" runat="server" Visible="true" Text=""
            AllowBlank="true" Width="250" SelectOnFocus="true" />
        </form>
        <ext:Button ID="btnSet" runat="server" Text="set" Icon="Printer" OnDirectClick="getDate" />
    </body>
    </html>
  4. #4
    Setting up the CurrentUICulture in Page_Init instead of Page_Load should solve the problem.

    Just there is a possibility in Ext.NET when the CurrentUICulture might be used before Page_Load.
  5. #5
    Quote Originally Posted by Daniil View Post
    Setting up
    <ext:ResourceManager runat="server" Locale="client" />
    causes localization according the current browser locale.
    Certainly, it's also possible to set up Locale:
    <ext:ResourceManager runat="server" Locale="it-IT" />
    Just a note, you can also set up a culture here:
    <%@ Page Language="C#" Culture="it-IT" %>
  6. #6
    Hi Daniil,
    i tried and finally got what I need by your precious info. I leave you just a note on my tests because I noted different behaviour depending from the instructions I used.
    I' ll try to be clear

    1. my operating system is Windows 7 in Italian ed settled in Italian env. for dates and numbers for both client and server (II7)
    2. in the example there are two differents instructions interested by the CurrentUICulture or Culture settings

    DateField1 beahviour in the form
    string d = DateField1.Value.ToString(); // beahviour in code behind
    DateField1 beahviour in the form depends from the setting of
    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
    the format of the return string from the instruction below depends on Culture value settled
    <%@ Page Language="C#" Culture="en-US" %>
    string d = DateField1.Value.ToString();
    to make both instructions (calendar use and return string from the field DateField1) work as I need (in italian or in english-US) I experienced that I need to set both Culture and CurrentUICulture.

    and finally, is it possible to set both beahviour globally without defining it in every page/code behind?

    hope this help or let me know anyway

    thanks again
    Last edited by Daniil; Jul 14, 2012 at 9:06 AM. Reason: Please use [CODE] tags for any code
  7. #7
    I think setting up
    <%@ Page Language="C#" Culture="it-IT" %>
    should be enough to get consistency with DateField.

    I am afraid I have not understood well what exactly issue you are facing with that option. Could you demonstrate with a sample?

    Quote Originally Posted by tanky65 View Post
    and finally, is it possible to set both beahviour globally without defining it in every page/code behind?
    You could set up the Culture in the Web.config.
    <system.web>
        <globalization culture="it-IT" />
  8. #8
    yes,

    the following example in which I set
    <%@ Page Language="C#" Culture="en-US" %>
    and

        
    protected void Page_Init(object sender, EventArgs e)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
        }
    everything works good:

    a) I handle the calendar in en-US standard, the format of the date displayed in the dateField1 is mm/dd/yyyy
    b) the text displayed in the textfield and return by the call of

    DateField1.Value.ToString();
    is in the right format is mm/dd/yyyy

    but

    if i set only

    <%@ Page Language="C#" Culture="en-US" %>
    and i comment out as follows

        
    protected void Page_Init(object sender, EventArgs e)
        {
            // System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
        }
    a) I handle correctly the calendar in en-US standard, the format of the date displayed in the dateField1 is mm/dd/yyyy
    but
    b) the text displayed in the textfield and return by the call of

    DateField1.Value.ToString();
    is in the wrong format, not en-US but italian format (my OS standard), dd/mm/yyyy

    in few words, the following instructions , if the os configuration is different by en-US
    DateField1.Value.ToString();
    returns a string in the format not handled by
    <%@ Page Language="C#" Culture="en-US" %>
    but conforme to the os itself

    this is just what I tested

    Follows the complete example where you can comment out the line in the Page_Init to see the two behaviour

    thanks and hope this is more clear

    [if you have the os in another language I should have sense to interchange it and en with yours and en ]

    <%@ Page Language="C#" Culture="en-US" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
    
        protected void Page_Init(object sender, EventArgs e)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                DateField1.Value = DateTime.Now;
            }
        }
    
        protected void getDate(object sender, DirectEventArgs e)
        {
             txtSelDate.Text = "day " + DateField1.Value.ToString();
        }
        
    </script>
    <!DOCTYPE>
    <html>
    <head id="Head1" runat="server">
        <title>Date example</title>
        <script type="text/javascript">
    
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        
        <ext:DateField ID="DateField1" FieldLabel="Date" runat="server">
        </ext:DateField>
    
        <ext:TextField ID="txtSelDate" FieldLabel="Date" runat="server" Visible="true" Text=""
            AllowBlank="true" Width="250" SelectOnFocus="true" />
        </form>
        <ext:Button ID="btnSet" runat="server" Text="set" Icon="Printer" OnDirectClick="getDate" />
    </body>
    </html>
  9. #9
    1. I was wrong here:
    <%@ Page Language="C#" Culture="en-US" %>
    Please use UICulture instead of Culture. But it won't solve the problem.

    2. Regarding the ToString method.

    The Value is a DateTime instance and the ToString method returns a string representation with the "G" format regardless from a current culture.
    http://msdn.microsoft.com/ru-ru/library/k494fzbf.aspx

    The "G" format doesn't match the DateField Format, therefore you see mismatching.

    To get the same string as you can see within the DateField in the browser you can use the RawValue method.
    txtSelDate.Text = "day " + DateField1.RawValue;
    or call the ToString method of the SelectedDate method with the following parameters:
    txtSelDate.Text = "day " + DateField1.SelectedDate.ToString(this.DateField1.Format, this.ResourceManager1.CurrentLocale);
    I would prefer to use the RawValue parameter.
  10. #10
    Hi @tanky65,

    Please clarify can we mark the thread as closed?
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 17
    Last Post: Jun 04, 2012, 10:56 AM
  2. [CLOSED] Default date format for Type="Date" RecordField
    By r_honey in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: May 29, 2012, 3:16 PM
  3. [CLOSED] DataField Control
    By rnfigueira in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 12, 2011, 10:30 PM
  4. [CLOSED] TextArea: format default value
    By RomualdAwessou in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 08, 2010, 11:42 AM
  5. Replies: 1
    Last Post: Dec 26, 2009, 7:59 AM

Tags for this Thread

Posting Permissions