Where can I set CurrentUICulture in an ASP.NET web page?
I was reading a resource that said:
CurrentUICulture must be set at the startup of a applicat开发者_JAVA技巧ion.
For an ASP.NET web page, where do I set this property appropriately?
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");
Web.config:
<globalization culture="en-US" uiCulture="en" requestEncoding="utf-8" responseEncoding="utf-8" />
Did you try:
Page.Culture = "your culture";
Page.UICulture = "your culture";
See Page.UICulture Property and Page.Culture Property on MSDN.
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
精彩评论