我在我的项目mainMaster页面中找到了imageButtons:
<asp:ImageButton ID="RU" ImageUrl="/Images/RU.png" runat="server" onclick="RU_Click">
<asp:ImageButton ID="USA" ImageUrl="/Images/USA.png" runat="server" onclick="USA_Click" />
这是OnClick功能:
protected void RU_Click(object sender, ImageClickEventArgs e)
{
Session["MyCulture"] = CultureInfo.CreateSpecificCulture("ru-RU");
Server.Transfer(Request.Url.LocalPath);
}
protected void USA_Click(object sender, ImageClickEventArgs e)
{
Session["MyCulture"] = CultureInfo.CreateSpecificCulture("en-AU");
Server.Transfer(Request.Url.LocalPath);
}
我也有两个.resx文件但是我用按钮
链接按钮是多么愚蠢<asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:Main, Name%>" />
答案 0 :(得分:1)
你的问题不明确,但让我向你澄清可能是你问题的一件事。
您只能在InitializeCulture
事件中设置文化:
protected override void InitializeCulture()
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-AU");
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-AU");
base.InitializeCulture();
}
答案 1 :(得分:-1)
使用此代码:
protected void RU_Click(object sender, EventArgs e)
{
SetCulture("ru-RU");
}
protected void USA_Click(object sender, EventArgs e)
{
SetCulture("en-UA");
}
public static void SetCulture(string culture)
{
CultureInfo cultureInfo = new CultureInfo(culture);
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
}
设置当前文化,因此本地化可以生效。