Forum  Core :: SDK (Vi...  Developing the ...  Thread.CultureInfo problem
Previous Previous
 
Next Next
New Post 1/14/2009 6:10 AM
  t.barton
14 posts
www.wasko.pl
No Ranking


Thread.CultureInfo problem 

Hi

First some simple code:

public partial class Form1 : Form
{
        public Form1()
        {
            InitializeComponent();
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = DateTime.Now.ToString();
        }
}

When application is run we set CultureInfo to English. Then we hit a button and in that moment CurrentCulture is back to Windows one and we get date in wrong format. What is the problem and what to do in order to prevent that from happening? Please help.

Regards.

 
New Post 1/14/2009 6:45 AM
  dubem1
1044 posts
1st Level Poster




Re: Thread.CultureInfo problem 

When working with string value of date, you must provide IFormatProvider like this:

TextBox1.Text = DateTime.Now.ToString(Context.CurrentUICulture)

Martin

 
New Post 1/14/2009 11:25 PM
  t.barton
14 posts
www.wasko.pl
No Ranking


Re: Thread.CultureInfo problem 
Modified By t.barton  on 1/15/2009 2:26:24 AM)

Hello and thanks for a reply.

I know that there is such option.

But our application is huge. We read date dozen of times in different places. More to say sometimes we apply ToString() to an object we dont know yet is datetime value. The number of possible changes and complication in code is too big. Also there are other culture sensitive methods.

Thats why there is Thread.CurrentThread.CurrentCulture to deal with the problem just with one simple code line, I guess.

Is there a way to set the culture for the application globally? (not mentioning setting it in web.config - we want to change it on a fly, when users log).

Regards

 
New Post 1/15/2009 12:40 AM
  t.barton
14 posts
www.wasko.pl
No Ranking


Re: Thread.CultureInfo problem 

I've found that using asp.net you can solve the problem by setiing the CurrnetCulture in GLobal.asax file for the whole "Application":

        protected void Application_AcquireRequestState(object sender, EventArgs e)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
        }

Then every culture sensitive method works fine.

How can I do same thing using VWG?

 
New Post 1/15/2009 7:59 AM
  izi.versano
191 posts
5th Level Poster




Re: Thread.CultureInfo problem 
Modified By izi.versano  on 1/15/2009 11:01:12 AM)

Hello ,

in web config try set the Languages element like so:

<WebGUI>
    <Languages>
      <Language Culture="en-US"/>
      <Language Culture="he-IL"/>
Regurds ,

Izi versano

The Visual Web Gui Team.

 
Previous Previous
 
Next Next
  Forum  Core :: SDK (Vi...  Developing the ...  Thread.CultureInfo problem
Assessment Bottom
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS