Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem Populating Session Variable

Posted on 2008-10-06
2
Medium Priority
?
210 Views
Last Modified: 2012-05-05
HI

I am trying to populate a session variable depeding on what was selected from a drop down.
e.g.
if they select PE from the drop down then the session variable becomes "PE_U", if they select RE then it becomes "RE_U"

I tried to do this using the code below but am having a strange problem. Basically when you select something from the drop down menu, the session variable populates with whats above it in the drop down.
E.g say the drop down has these options:

PE
HF
Infra
RE

Now when HF is selected the session value should be "HF_U" however it becomes "PE_U" (the one above it) if "Infra" is selected then the session value becomes "HF_U" again the one above it.

Any ideas on why this is happening?

Thanks in advanced
Protected Sub ddlAdvisorUniverse_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
		If ddlAdvisorUniverse.SelectedValue = 1 Then
			Session("AdvisorUniverse") = ""
			Session("AdvisorUniverse") = "PE_U"
		ElseIf ddlAdvisorUniverse.SelectedValue = 3 Then
			Session("AdvisorUniverse") = ""
			Session("AdvisorUniverse") = "RE_U"
		ElseIf ddlAdvisorUniverse.SelectedValue = 2 Then
			Session("AdvisorUniverse") = ""
			Session("AdvisorUniverse") = "HF_U"
		ElseIf ddlAdvisorUniverse.SelectedValue = 4 Then
			Session("AdvisorUniverse") = ""
			Session("AdvisorUniverse") = "INF_U"
		Else
			Session("AdvisorUniverse") = "NONE"
		End If
	End Sub
 
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
		Response.Write(Session("AdvisorUniverse"))
	End Sub
 
	<asp:Label ID="Label1" runat="server" Text="None"></asp:Label>
	<asp:DropDownList ID="ddlAdvisorUniverse" runat="server" onselectedindexchanged="ddlAdvisorUniverse_SelectedIndexChanged" AutoPostBack="true">
	<asp:ListItem Value=""></asp:ListItem>
	<asp:ListItem Value="1">PE</asp:ListItem>
	<asp:ListItem Value="2">HF</asp:ListItem>
	<asp:ListItem Value="4">Infra</asp:ListItem>
	<asp:ListItem Value="3">RE</asp:ListItem>
	</asp:DropDownList>

Open in new window

0
Comment
Question by:patelajk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
crazyman earned 500 total points
ID: 22648889
Page_Load will fire before selectedindex changed, so you are writing out the previous value.

Override OnPreRender and write it out there.
0
 
LVL 14

Expert Comment

by:Binuth
ID: 22648903
try to write  Response.Write(Session("AdvisorUniverse")) after ddlAdvisorUniverse_SelectedIndexChanged event
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question