//master.cs
protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
{
//alert box
string message = "Some Content of the Site are only in English. Do you want to continue?";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("return confirm('");
sb.Append(message);
sb.Append("');");
Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "alert", sb.ToString());
//alert end
//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);
}
//master Page
<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>
每当用户从英语更改为西班牙语时,我都想显示一个警告框。这是一种奇怪的行为,此代码无法正常工作,它不会在所选索引更改时向我显示任何警报框,但是如果我将警报框代码粘贴到页面加载事件中,它会起作用。页面加载与此有关吗?其次,是否可以记住答案,即如果用户选择了一个复选框说记住我,我应该记住用户在整个会话期间选择的是还是否。关于第二个问题的任何建议都会有所帮助。但是请帮我找出上述代码没有按预期工作的原因。