我无法改变的.aspx页面的文化。
当我使用page指令顶部指定文化:
<%@页面语言=C#AutoEventWireup =真正的codeBehind =Index.aspx.cs继承=VideoPlayerPrototype.Index文化=UR -PK的UICulture =UR-PK%>
一切正常。
我想要做的,就是能够当用户点击一个链接更改本地化。
链接:
< ASP:ImageButton的ID =lang_ur-PK
旗 - pakistan.png的〜/内容/图像/的ImageUrl =
=服务器
的CssClass =语言
身高=64PX
WIDTH =64PX
的OnClick =setLanguage/>
setLanguage方式:
保护无效setLanguage(对象发件人,EventArgs的)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(UR-PK);
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(UR-PK);
的Response.Redirect(Request的);
}
调用此code只是重新加载页面并不会加载正确的语言。
我有存储在App_LocalResources文件和App_GlobalResources文件.resx文件:
Index.aspx.resx,Index.aspx.en.resx,Index.aspx.ur-PK.resx,Index.aspx.ur.resx等。
下面是控制的,必须本地化的一个例子:
< ASP:标签ID =lblInfoWelcomeMsg=服务器
文本=<%$资源:LocalizedText,Summary_Info_WelcomeMsg%>>< / ASP:标签>
感谢您
解决方案你必须在你的code添加这个方法背后
保护覆盖无效InitializeCulture()
{
System.Threading.Thread.CurrentThread.CurrentUICulture =新System.Globalization.CultureInfo(UR-PK);
System.Threading.Thread.CurrentThread.CurrentCulture =新System.Globalization.CultureInfo(UR-PK);
base.InitializeCulture();
}
它更好的,你可以让的BasePage
类,并添加那里,然后的BasePage
可以通过每个页面
I'm unable to change a culture of .aspx page.
When I specify the culture by using page directive at the top:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="VideoPlayerPrototype.Index" Culture="ur-PK" UICulture="ur-PK" %>
Everything works as expected.
What I'd like to do, is to be able to change localisation when user clicks on a link.
Link:
<asp:ImageButton ID="lang_ur-PK"
ImageUrl="~/content/image/flag-of-pakistan.png"
runat="server"
CssClass="language"
Height="64px"
Width="64px"
OnClick="setLanguage" />
setLanguage method:
protected void setLanguage(Object sender, EventArgs e)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("ur-PK");
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("ur-PK");
Response.Redirect(Request.Path);
}
Invoking this code just reloads the page and doesn't load the correct language.
I have .resx files stored in App_LocalResources and App_GlobalResources:
Index.aspx.resx, Index.aspx.en.resx, Index.aspx.ur-PK.resx, Index.aspx.ur.resx etc.
Here is an example of control that must be localised:
<asp:Label id="lblInfoWelcomeMsg" runat="server"
Text="<%$ Resources:LocalizedText, Summary_Info_WelcomeMsg %>"></asp:Label>
Thank you
解决方案you have to add this method in your code behind
protected override void InitializeCulture()
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ur-PK");
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ur-PK");
base.InitializeCulture();
}
Its better you can make BasePage
class and add there and then BasePage
can be inherited by each page