我希望有一个双语网站(英文和德文)使用 Resource.resx 我可以成功地将页面的语言改为德语但我不能回到英语。这是我的代码:
protected void Page_Load(object sender, EventArgs e)
{
Session["Lan"] = DropDownList1.SelectedItem.Value.ToString();
if (Session["Lan"].ToString() == "de-DE")
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("de-DE");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");
Label2.Text = Resources.Resource.Here;
HyperLink1.Text = Resources.Resource.Signup;
}
我该如何解决这个问题?
修改 我已将Dropdownbox的Autopost属性设置为true,并将我的代码块添加到 ispostback ,如下所示:
Session["Lan"] = DropDownList1.SelectedItem.Value.ToString();
if (Page.IsPostBack)
{
if (Session["Lan"].ToString() == "de-DE")
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("de-DE");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");
Label1.Text = Resources.Resource.Quick_routes_offers_the_opportunity_to_manage_and_analyze_the_recorded_routes_The_format_of_your_route_must_be_GPX_format_;
Label2.Text = Resources.Resource.Here;
HyperLink1.Text = Resources.Resource.Signup;
}
}
但我认为如果语言不是“de”我的标签的原始文本应该出现,为什么这个想法不起作用?
答案 0 :(得分:0)
试试这个,如果在<。p>下面放else
else
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
Label1.Text = Resources.Resource.Quick_routes_offers_the_opportunity_to_manage_and_analyze_the_recorded_routes_The_format_of_your_route_must_be_GPX_format_;
Label2.Text = Resources.Resource.Here;
HyperLink1.Text = Resources.Resource.Signup;
}