I've probably implemented this wrong or have something in the wrong order. When I use code below, the session variable doesn't get updated properly.
When the code first runs there is no session, when you select a language from the drop down the code fires to update the session variable and things post back to the page.
So when you start, the language in the dropdown is english and the debug label is updated to say there is no session. Select french, it autoposts then redraws the page. The changelanguage() code alters the label currentlang with the value from the dropdown ("FR") but when the page reloads the session is still empty. If you then select Espanol in the dropdown the page reloads the page the currentlang label has "ES" and session variable now has something in it -- but its "FR". if you keep select another langauge it seems the session variable is always one step behind.
Heres the code:
-wbochar
When the code first runs there is no session, when you select a language from the drop down the code fires to update the session variable and things post back to the page.
So when you start, the language in the dropdown is english and the debug label is updated to say there is no session. Select french, it autoposts then redraws the page. The changelanguage() code alters the label currentlang with the value from the dropdown ("FR") but when the page reloads the session is still empty. If you then select Espanol in the dropdown the page reloads the page the currentlang label has "ES" and session variable now has something in it -- but its "FR". if you keep select another langauge it seems the session variable is always one step behind.
Heres the code:
Code:
<%@ Page language="c#" debug=true %>
<html>
<head>
<title>Session Screwy</title>
<script runat=server language="c#">
void Page_load(Object sender, EventArgs e)
{
if (Session["Language"]!=null)
{
DebugDump.Text="Session Not Empty: "+Session["Language"].ToString();
}
else
{
DebugDump.Text="Session Empty";
}
}
void ChangeLanguage (Object sender, EventArgs e)
{
Session["Language"]=dropLanguage.SelectedItem.Value.ToString();
CurrentLang.Text=Session["Language"].ToString();
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:Label id="CurrentLang" runat="server"></asp:Label>
<asp:DropDownList AutoPostBack=True OnSelectedIndexChanged="ChangeLanguage" id="dropLanguage" Runat="server" Font-Size="7" Height="14">
<ASP:LISTITEM Value="EN" text="English" />
<ASP:LISTITEM Value="FR" text="Français" />
<ASP:LISTITEM Value="ES" text="Espanol" />
</asp:Dropdownlist></li>
</P>
<asp:Label id="DebugDump" runat="server"></asp:Label>
</form>
</body>
</html>
-wbochar