2010-03-11 48 views
2

我在讀的資源,說:我在哪裏可以在ASP.NET網頁中設置CurrentUICulture?

CurrentUICulture must be set at the startup of a application.

對於ASP.NET網頁,我在哪裏適當地設置該屬性?

+0

你指的是什麼文件呢? – 2010-03-11 10:06:18

+0

如果任何給定的答案是正確的,您能否將其標記爲這樣? – 2010-03-22 18:27:53

回答

3

在一個網頁,你可以在頁面指令設置Culture和UICulture:

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

它沒有在應用程序啓動時進行設置。

更新:正如克里斯托弗·克拉斯在評論中提到,你可以在Page_Init設置它在代碼:

System.Threading.Thread.CurrentThread.CurrentCulture = 
    new System.Globalization.CultureInfo("en-US"); 
System.Threading.Thread.CurrentThread.CurrentUICulture = 
    new System.Globalization.CultureInfo("en-US"); 
+0

我可以在代碼隱藏時動態更改它嗎? – Ricky 2010-03-11 10:22:36

+1

是的,最好在Page_Init(): System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(「en-US」); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(「en-US」); – 2010-03-11 11:09:25

3

Web.config文件:

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

我做到這一點,頁面本身

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 
相關問題