简体   繁体   English

在ASP.NET中设置文化

[英]Setting the Culture in ASP.NET

I have an asp:literal: 我有一个asp:literal:

<asp:Literal id="language" OnClick="changeLangauge" Text="<%$ Resources:Translate, switchLanguage %>" runat="server"/>

When it is clicked it switches the language: 单击后,将切换语言:

public void ChangeLanguage(Object sender, EventArgs e)
{
  string lang = langauge.Attribues["class"];
  language.Attributes.Remove("class");
  if (lang.Equals("fr-CA"))
  {
    language.Attributes.Add("class", "en-US");
    Session["lang"] = "en-US";
  }
  else
  {
    language.Attributes.Add("class", "fr-CA");
    Session["lang"] = "fr-CA";
  }
}

I have overrided InitializeCulture, to set the culture based on Session["lang"]. 我已经覆盖了InitializeCulture,以基于Session [“ lang”]设置区域性。 The problem is InitializeCulture gets called before ChangeLanguage. 问题是在ChangeLanguage之前调用了InitializeCulture。 How do I get around this problem? 我该如何解决这个问题?

I have tried to get the class value from asp:Literal control from inside InitializeCulture like this: 我试图像这样从InitializeCulture内部从asp:Literal控件获取类值:

public void InitializeCulture(..)
{
    ...
    String selectedLanguage = Request.Form["language"]
    ...
}

but it always returns null. 但它始终返回null。

My suggestion to get around this is to use AJAX. 我的建议是使用AJAX。 Asynchronisly call your ChangeLanguage function when the language literal gets clicked. 单击语言文字时,异步调用您的ChangeLanguage函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM