views:

177

answers:

4

I was reading a resource that said:

CurrentUICulture must be set at the startup of a application.

For an ASP.NET web page, where do I set this property appropriately?

+2  A: 

Web.config:

<globalization culture="en-US" uiCulture="en" requestEncoding="utf-8" responseEncoding="utf-8" />
bang
+2  A: 

In a web page, you can set Culture and UICulture in the page directive:

<%@ Page .... Culture="en-US" UICulture="en-US" %>

It doesn't have to be set at application startup.

Update: And as Kristof Claes mentions in a comment, you can set it in code during Page_Init:

System.Threading.Thread.CurrentThread.CurrentCulture =
    new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentUICulture =
    new System.Globalization.CultureInfo("en-US");
Ronald Wildenberg
Can I dynamically change it at code-behind?
Ricky
Yes, preferably in the Page_Init(): System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
Kristof Claes
+1  A: 

Did you try:

  Page.Culture = "your culture";
  Page.UICulture = "your culture";

See Page.UICulture Property and Page.Culture Property on MSDN.

Jakob Gade
+1  A: 

I do this, on the page itself

Protected Overrides Sub InitializeCulture()
    If Not Me.IsPostBack Then
                   Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo(var.Sess.lang)
        Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.CreateSpecificCulture(Threading.Thread.CurrentThread.CurrentUICulture.Name)
    End If
    MyBase.InitializeCulture()
End Sub
Fredou