views:

338

answers:

2

Hi how can I set culture information on a user control? I have set up the resource file but I am unable to override the InitializeCulture() as it is not available in System.Web.UI.UserControl. Can someone point me in the right direction? I want to this programatically. Thank you.

A: 

Yo need to change the culture of the current thread

flalar
+1  A: 

In the PageLoad event of your user control you can set the culture of the current thread:

Me.Culture = "en-US"

Any internal framework calls after this point will use the current culture set for this thread, so for example the Convert.ToDouble() call will work here:

Me.Culture = "en-US"
Dim num as Double = Convert.ToDouble("1,000.50")

...but this would not work:

Dim num as Double = Convert.ToDouble("1.000,50")

... if we set the culture to French Canadian:

Me.Culture = "fr-CA"
Dim num as Double = Convert.ToDouble("1.000,50")

... this will work and correctly parse the string because the default decimal separator for the French Canadian culture is a comma.

wweicker