 |
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
|
|
|

May 30th, 2007, 11:16 AM
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 2nd, 2007, 06:14 AM
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dear,try to check it after declaring session variable in Global.asax file.
|

June 3rd, 2007, 09:35 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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
|

June 3rd, 2007, 11:35 PM
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 4th, 2007, 10:47 AM
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

June 4th, 2007, 11:05 AM
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|
 |