Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2007, 11:16 AM
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



 
Old June 2nd, 2007, 06:14 AM
Authorized User
 
Join Date: Jan 2007
Location: Islamabad, Punjab, Pakistan.
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aliirfan84
Default

Dear,try to check it after declaring session variable in Global.asax file.


 
Old June 3rd, 2007, 09:35 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This sounds like a simply issue with browser caching. When user hits back, they are getting the previous page from cache instead of from the server so that Y/N value isn't actually getting read.

If you set the Legalese page to immediate expiration then when the user back-arrows the browser will be forced to retrieve the page from the server (instead of cache). In the legalese page load, check for session value of "Y", and if it is, redirect to the PDF list so they get the desired "back" behavior.

I'm not sure how this will behave given that your legalese page is doing a postback before redirecting to the PDF, however. You might encounter some issues with that, but it's worth a try.

-Peter
 
Old June 3rd, 2007, 11:35 PM
Authorized User
 
Join Date: Jan 2007
Location: Islamabad, Punjab, Pakistan.
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aliirfan84
Default

Dear, u should set the property like this on page load:

Response.Cache = "no-cache";

This will not cache a page. But it might not work on system which already cached these pages. So u should first clear ur IE history then try. Hope will be solution for u.

Regard
Ali Irfan

 
Old June 4th, 2007, 10:47 AM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Ali & Peter,

Your point about browser caching makes perfect sense, but when I try:
    Response.Cache = "no-cache"
in the VB, I get a message: Property 'cache' is 'Read-Only'.

Also, I can't find how to clear browser history.

I figured you might mean that it goes in the HTML, and I tried putting this, which I found via Google, in the HTML:
    <% Response.CacheControl = "no-cache" %>
    <% Response.Expires = -1 %>
but it has no effect.

I am just not seeing anything useful in various Google searches.

This ins't a showstopper of an issue, and I could always kluge something up using the SQL database, but it seems like this should be doable. I apologize for my igorance, and appreciate your help.


 
Old June 4th, 2007, 11:05 AM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Peter & Ali,

I panicked too soon - a silly misplacement of a line of code was to blame. For other newbies, here's what works:

Based on your replies, I found the following via Google, and put it in Page_Load:
        Response.Cache.SetCacheability(HttpCacheability.No Cache)
        Response.Cache.SetAllowResponseInBrowserHistory(Fa lse)
This allows the subsequent logic in Page_Load (in my post of 05/30/2007 : 11:16:45 AM below) to be run when the page is redisplayed, which obtains the current value of the session var.

Thanks again for your help!





Similar Threads
Thread Thread Starter Forum Replies Last Post
session and variable... badboy1 ASP.NET 3.5 Basics 1 August 3rd, 2008 09:14 AM
Can we get value of a session variable KamalRaturi ASP.NET 2.0 Professional 3 September 14th, 2006 03:33 PM
Session Variable youyou_hym Dreamweaver (all versions) 4 January 20th, 2005 11:48 AM
Session variable anuradha80 General .NET 3 November 4th, 2004 12:39 AM
Session Variable mcdowell BOOK: Beginning ASP 3.0 5 June 20th, 2004 05:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.