0

通过公司页面在我的登录页面中选择任何语言时,一切正常,但是当我单击公司页面中的任何按钮时,它会以默认语言(英语)返回。我想以我选择的语言维护它

请帮忙。

公司.aspx.cs

 protected void Page_Load(object sender, EventArgs e)
        {


          if (!IsPostBack)
            {

                if (Session["language"] != null)
                {
                    string language = Session["language"].ToString();
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(language);
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);

                }
                string Flag = Session["Flag"].ToString();
                if (Flag == "Y")
                {
                    Session["Flag"] = "N";
                    Server.Transfer(Request.Path);

                }
                Session["Flag"] = "Y";
           }
       }    

登录.aspx

  <div>
             <asp:DropDownList ID="ddlLang" runat="server"AutoPostBack="True"
             OnSelectedIndexChanged="ddlLang_SelectedIndexChanged">
             <asp:ListItem Text="English" Value="en-US"></asp:ListItem>
             <asp:ListItem Text="French" Value="fr-FR"></asp:ListItem>
             <asp:ListItem Text="Spanish" Value="es-ES"></asp:ListItem>
             <asp:ListItem Text="Chinese" Value="zh-SG"></asp:ListItem>
             </asp:DropDownList>
          </div>

登录.aspx.cs

  protected void Page_Load(object sender, EventArgs e)
       {
         if (!Page.IsPostBack)
         {
        if (Session["language"] != null)
                {
                    ddlLang.SelectedValue = Session["language"].ToString();
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture                                  (ddlLang.SelectedValue);
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(ddlLang.SelectedValue);
                }
                else
                {
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture                        (ddlLang.SelectedValue);
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(ddlLang.SelectedValue);
                }
               Session["Flag"] = "Y";
     }
   }





protected void ddlLang_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlLang.SelectedValue == "fr-FR")
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");
                Session["language"] = ddlLang.SelectedValue;
                Server.Transfer(Request.Path);
            }
            if (ddlLang.SelectedValue == "zh-SG")
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("zh-SG");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-SG");
                Session["language"] = ddlLang.SelectedValue;
                Server.Transfer(Request.Path);
            }
            if (ddlLang.SelectedValue == "es-ES")
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("es-ES");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-ES");
                Session["language"] = ddlLang.SelectedValue;
                Server.Transfer(Request.Path);
            }
            else
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
                Session["language"] = ddlLang.SelectedValue;
                Server.Transfer(Request.Path);
            }

        }
4

1 回答 1

1

我认为这是一个简单的错误

Corporation.aspx.cs 中的if (!IsPostBack)将仅在首次加载时执行。所以基本上所有的设置都是在第一次加载时完成的。

在您点击页面上的某个按钮后,将触发一个回发,该回发将执行 Page_Load。但是这一次,因为它是一个回发,所以你的语言代码没有被执行......

于 2015-01-23T02:12:07.513 回答