language selection dropdown autopostback not working

D

DC Gringo

I have a language selector in a dropdownlist that I want to set a session ID
with. It seems to post and accept the value, but my condition statement
doesn't seem to read the session ID and show me my alternate language code.

Here's my dropdownlist:

<ASP:DROPDOWNLIST ID="ddlLanguageSelection1" RUNAT="server"
AUTOPOSTBACK="True"
ONSELECTEDINDEXCHANGED="ddlLanguageSelection_SelectedIndexChanged"
ENABLEVIEWSTATE="True" FONT-SIZE="8pt">
<ASP:LISTITEM VALUE="en" SELECTED="True">English</ASP:LISTITEM>
<ASP:LISTITEM VALUE="fr">Français</ASP:LISTITEM>
<ASP:LISTITEM VALUE="po">Português</ASP:LISTITEM>
<ASP:LISTITEM VALUE="es">Español</ASP:LISTITEM>
</ASP:DROPDOWNLIST></SPAN></ASP:pANEL>

Sub ddlLanguageSelection_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs)
' set up the session variable for population of dependent list
Dim ddl As DropDownList
ddl = sender
Session("sID") = ddlLanguageSelection1.SelectedItem.Value
End Sub

My trace/debug shows that the value is assigned to the session variable:

-----------------------------

Session Key = sID
Type = System.String
Value = es (which is spanish)
------------------------------

What's happening is that I start with English, then if I select Spanish
(value of "es") it shows Spanish in the dropdownlist, but doesn't give me
Panel2.Visible...it still gives me panel1.Visible as if session("sID") were
still "en". If I change it back to English, then it shows me both panels!!!!

My index.aspx.vb webform has the following code:
------------------------------

If Not Page.IsPostBack Then
Session("sID") = "en"
End If

If Session("sID") = "en" Then
mainHeader1.Panel1.Visible = True

ElseIf Session("sID") = "es" Then
mainHeader1.Panel2.Visible = True
End If
 
B

bruce barker

the SelectedIndexChanged event fires after form load (see documentation of
control lifecycle), so you need to reset the panel attributes in the change
event.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top