Solved

Problem Populating Session Variable

Posted on 2008-10-06
2
201 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
2 Comments
 
LVL 13

Accepted Solution

by:
crazyman earned 125 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Displaying a web form as a modal popup dialog box. 4 30
Web site error 3 35
Deploying to Azure 3 26
jQuery - following an example but can I save data server side? 20 46
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

816 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now