Losing session variable in popup

J

Joe Molloy

Hi,

This isn't a mission critical question but I thought I'dl throw it out there
for your feedback as it's a bit curious.

I have developed a shopping cart for an application I'm working on which is
loosely based on the e-commerce example in the quickstarts tutorial.

In the cart display I have provided functionality so that when a user clicks
on a product name a popup is opened with the full product details displayed.
Baiscally, a javascript function with the product id as an argument opens
the popup windw with the product id in the querystring so that I can display
the product details in the popup.

It then occured to me that it would be nice to provide a dropdown list in
the popup window to dsiplay the other itmes in the cart so that the user
could view the details of any of the other cart items by selecting it from
this list.

Now, my shopping cart values are stored in a session variable of a type that
exposes the icollection interface - the cart display itself is simply a
datalist databound to this icollection so I figured that I should be able to
do the same with and bind the dropdownlist.

However, when I tried my dropdown remained empty and after some detective
work I discovered that it was because my session variable appeared to be
empty in the popup page despite the fact that the shopping cart page could
read it without any problem.

So, my question is about the scope of session variables really I suppose -
does anyone have any thoughts about why my session variable wouldn't be
available to the popup window?

I look forward to hearing your thoughts,

Joe
 
J

Joe

Can you please post the relevent sample code? specifically, the code that
generates the pop-up and then the code in the pop-up itself.
 
W

William LaMartin

Your query sounded like something I might like to do, so I gave it a try.
The following worked for me.

I created two aspx pages, PopUpTest.aspx and PopUpItem.aspx. The pertinent
code for both pages is below.

When PopUpText.aspx loads, three session variables are set as seen in the
code. Then when you click the button on the page, JavaScript is run to open
the page PopItem.aspx in a new, sized window. On PopItem.aspx is a label
containing the value for Session("PopUpTest_Name") and a dropdown list box
containing two items with values Session("Item1") and Session("Item2") .

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

Code on PopUpTest.aspx :

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Session("PopUpTest_Name") = "Testing Session Variables"
Session("Item1") = "A " & Now.ToString
Session("Item2") = "B " & Now.ToString
End Sub

Private Sub btnPopUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPopUp.Click
Dim scriptString As String
'scriptString = "<script language=JavaScript>
window.open('PopUpItem.aspx')"
scriptString = "<script language=JavaScript>
window.open('PopUpItem.aspx','test','width=500,height=400,resizable=yes,scro
llbars=yes');"
scriptString = scriptString & "test.focus();"
scriptString = scriptString & "</script>"
RegisterStartupScript("newwindow", scriptString)
End Sub
---------------------------

Code on PopUpItem.aspx:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.Label1.Text = "Session Variable 'PopUpTest_Name' has value: " &
Session("PopUpTest_Name")
Me.DropDownList1.Items.Clear()
Me.DropDownList1.Items.Add(Session("Item1"))
Me.DropDownList1.Items.Add(Session("Item2"))
End Sub
 

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