コーポレーションページからログインページの言語を選択するとすべて正常に動作しますが、コーポレーションページのボタンをクリックするとデフォルト言語(英語)に戻ります。選択した言語で維持したい
助けてください。
Corporation.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);
}
}