//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>
每当用户从英文更改为西班牙语时,我想显示一个警告框。 它是一个奇怪的行为,这段代码不工作,它不会显示任何警告框在选定的索引更改,但如果我粘贴警告框代码在页面加载事件它的作品。 pageload是否必须对此做任何事情? 其次,有可能记住答案,即如果用户选择了记住我的复选框,我应该记住用户是否在整个会话中选择了YES或NO。 关于第二个问题的任何建议将有所帮助。但请帮我找出上述代码无法按预期工作的原因。下拉菜单SelctIndexChange不按预期方式工作
采取措施,它没有表现出任何警觉......我必须使用Page.ClientScript..If我只用ClientScript..it显示在目前的情况下不exsist .. – Scorpio
该代码为我工作,做你会得到任何错误信息,并且你为下拉菜单设置了“AutoPostback = true”吗? – Raghuveer
yep AutoPostBack =“True”无错误msg – Scorpio