代码背后:
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
ddlLanguage.SelectedValue = Thread.CurrentThread.CurrentCulture.Name;
}
}
protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlLanguage.SelectedValue == "es-ES")
{
mdlPopup.Show();
}
//Sets the cookie that is to be used by Global.asax
HttpCookie cookie = new HttpCookie("CultureInfo");
cookie.Value = ddlLanguage.SelectedValue;
Response.Cookies.Add(cookie);
//Set the culture and reload the page for immediate effect.
//Future effects are handled by Global.asax
Thread.CurrentThread.CurrentCulture = new CultureInfo(ddlLanguage.SelectedValue);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(ddlLanguage.SelectedValue);
//Server.Transfer(Request.Path);
}
protected void OKButton_Click(object sender, EventArgs e)
{
Server.Transfer(Request.Path);
}
ASPX 页面:
<asp:DropDownList ID="ddlLanguage" class="langpnl" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ddlLanguage_SelectedIndexChanged">
<asp:ListItem Value="en-US">Eng</asp:ListItem>
<asp:ListItem Value="es-ES">Esp</asp:ListItem>
</asp:DropDownList>
<ajaxToolkit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="testhidden"
PopupControlID="pnlPopup" OkControlID="OKButton" />
<asp:Panel ID="pnlPopup" runat="server" Width="500px" Style="display: none">
All content may not be in Spanish.
<asp:Button ID="OKButton" runat="server" Text="OK" OnClick="OKButton_Click" />
</asp:Panel>
<asp:HiddenField ID="testhidden" runat="server" />
我正在尝试根据下拉框中的选择设置语言。但是,如果用户选择西班牙语,我想显示一个带有 msg 的弹出模式,一旦按下按钮 OK,我想回发整个页面。目前我能够显示弹出窗口,但页面从未刷新,因此语言仍然没有改变。在后面的代码中,如果我从 OK 按钮中删除 server.transfer 并将其放在 SelectIndexChange 中,则页面回发正在工作,但没有弹出消息。我认为页面在弹出窗口执行后得到回发,因此它永远不会显示。 ..请需要一些帮助,自从过去 3 天以来,我一直在头疼。