//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>
Whenever the user changes from English to Spanish I want to display an alert box.
Its a weird behavior, this code is not working its not showing me any alert box on selected index change but if I paste the alert box code in the page load event it works. Is the pageload has to do anything with this?
Secondly is it possible to remember the answer i.e if the user selects an checkbox saying remember me, I should remember whether the user selected YES or NO throughout the session.
any suggestions on the second questions will help. But please help me find the reason why the above code is not working as expected.
Try the following code in your
dropdownSelected index changed eventto show the alert box