View Single Post
  #1 (permalink)  
Old May 30th, 2007, 11:16 AM
LenexaKS LenexaKS is offline
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Session variable weirdness

Hi all,

I have a weird situation where in a button click event, the setting of a session variable isn’t working.
The user is on ItemList.aspx and clicks a Select link in a GridView to indicate that s/he wants to see a particular PDF file. This works; the logic just does:
        Session("Path") = PathToPDF
        Session("UserClickedAccept") = "N"
        Response.Redirect("Legalese.aspx")

On Legalese.aspx, in Page Load, the variable
Session(“UserClickedAccept”) is N as expected. (I have a temporary display of the var in page load to verify this.)
The user ignores the legal verbiage displayed on the page and clicks the AGREE button.
    Protected Sub imgbtnAccept_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgbtnAccept.Click
        Dim Path As String = Session("Path")
        Session("UserClickedAccept") = "Y" ‘<-- the problem line
        Response.Redirect(Path)
    End Sub

It displays the correct PDF, but when the user finishes reading the PDF and clicks the back-arrow to return, my temporary display statement in Legalese.aspx’s page load shows the session var = “N”.

When, as an experiment, I redirect towards an aspx page which is IN the solution, it shows “Y” as expected:
Response.Redirect("ErrorPage.aspx?blah " & CType(Session("UserClickedAccept"), String))

Is there something about redirecting to a PDF file outside the solution’s folder that somehow throws it off?

The reason behind all this is, I was just trying to be a little user-friendly and say, in Legalese.aspx’s Page_Load, “If the session var = Y, the user already clicked ACCEPT and read the PDF, so don’t redisplay the legalese – just return immediately to the list of PDFs”, to save the user another back-arrow click.
Here’s what’s in Legalese.aspx’s Page_Load… it’s pretty vanilla.
        If Session("UserClickedAccept") Is Nothing Then
            'Shouldn't happen, but display this page for user to click Accept
            Response.Write("<Script language=Javascript> window.alert('" & _
                "Temp display - page load nothing" & _
                "') </Script>")
        Else
            If CType(Session("UserClickedAccept"), String) = "N" Then
                'Display this page for the user to click Accept
                Response.Write("<Script language=Javascript> window.alert('" & _
                    "Temp display - page load N" & _
                    "') </Script>")
            Else
                'We're returning from a display of a document - don't bother showing this page, just return to doc list:
                Response.Write("<Script language=Javascript> window.alert('" & _
                    "Temp display - page load " & CType(Session("UserClickedAccept"), String) & _
                    "') </Script>")
                Session("UserClickedAccept") = Nothing
                Response.Redirect("ItemList.aspx")
            End If
        End If

I really appreciate any suggestions you might have.
Thanks, LenexaKS