ASP .Net back button

Hi All,

I have a situation where I collect parameters for a Crystal Report on 1 page, then redirect to a second page to display the crystal report.

I have a link that goes from the second page back to the first page, and am trying to maintain the parameters (if I hit the back button in IE this works automatically).

I've been using the following javascript to do this, however on a page where I show/hide controls the back code isn't working properly.  For some reason it selects the 2nd most recent page instead of the first page.

EG: history:

crystal_print
myparam
myparam   -- Goes to this page instead of the one above it, shows incorrect parameters selected.

My question is why?  Am also okay with implementing another way to do the back button, but the history.go was the closest thing I've found to it.

in my param page:
Session("url") = Request.UrlReferrer.PathAndQuery
 
in my print page:
s = "<script language=""javascript"">history.go('http://" + Request.UrlReferrer.Authority + Session("url").ToString + "');</script>"

Open in new window

LVL 42
Kyle AbrahamsSenior .Net DeveloperAsked:
Who is Participating?
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
Forgot I was already in the codefile, LOL.

         s = "<script language=""javascript"">history.go(" + (-1 * Session("histcount")).ToString() + ");</script>"

Thanks very much for the help.  
0
 
sunithnairCommented:
Please try this

in my print page:
s = "<script language=""javascript"">history.back(-1);</script>"

Open in new window

0
 
sunithnairCommented:
Try this link for more information http://docs.sun.com/source/816-6408-10/history.htm
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
Won't work.

Since I'm using crystal reports if I drill down or anything it will just go back to the page before it.  (EG: drilldown go back -1 is the main report.)  I need to jump directly back to the main parameter page.
0
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
Actually another comment on this . . . if I drill down and use the back button the same behavior as the go(-1) is observed . . . so how do I ALWAYS jump back to the first page that says myparam
0
 
sunithnairCommented:
How many pages involved? 1st Page (Param page) and 2nd Page (Report page) Is there are other page in the middle?
0
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
no other pages in the middle, but the way the report viewer works it creates another page every time you do something (usually drill down or view a sub report).  Ergo it's possible to have N print pages above the param page.  I'm observing this behavior mostly when going back and forth a few times.

Order is:
parm page --1
print page
print page
param page (different settings) -- 2
print page
param page (same as 1) -- 3
print page
param page -- Random settings between param page 1 and 2

If I do use the back button after the third time though it works fine.  

When I view the history (in IE7, blue down arrow next to "forward" button) I can see it's jumping back to the 2nd page and not the first.

Attached is a screen shot of the history.

history.jpg
0
 
sunithnairCommented:
Can you try this in your param page so that we only set the session the first time and not always and try the history.go option that you had earlier
if Request.UrlReferrer <> Null && Session("url") <> Null then
Session("url") = Request.UrlReferrer.PathAndQuery
end if

Open in new window

0
 
sunithnairCommented:
I am not sure if there is an syntax error in the above code or not
0
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
The plot thickens . . .

the param page comes from a server.transfer, so on the first postback the URL changes.  The above won't work if I run with defaults, then do a post back to change the parameters and show other controls.
0
 
sunithnairCommented:
instead of server.transfer why dont you try and submit the form if that solves the problem?
0
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
Reports page has a hyperlink column in a grid that transfers to the homepage.  My question is why isn't the javascript going to the first page as expected with the location?  

Also, even we only set it on the first page, it will always go back to the first pages parameters.  I want to be able to go back to the parameters that were most recently selected by utilizing the back button.  Is there a way I can run through the history to get a count of pages between here and where I need to be?
0
 
sunithnairCommented:
Hmm your post @23632678 got me thinking if that is possible at all and I did some research on that and found that you have history.length which you can use to see the number of history items in the current browser window. If this helps.. I would also suggest you to have a session variable to store the number of times the page has been posted back anf you could use this number to go back in the history like this
s = "<script language=""javascript"">history.back(-<%=Session('noOfPostbacks')%>);</script>"

Open in new window

0
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
Had to fix my local crystal reports, was tired of copying up to the server.

Anyway:

Getting an error when Writing out the number.
s = "<script language=""javascript"">history.go(<%'-1 * Session(""histcount"")'%>);</script>"
which yields
"<script language="javascript">history.go(<%'-1 * Session("histcount")'%>);</script>"

I have tried copying your's straight in but it also threw an error.  


0
 
sunithnairCommented:
So is the solution working now?
0
 
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
Yep.  Works everytime, regardless of how many times I drill into the report or modify the data.  I took my own comment as the solution but made yours the assisted solution so you get the points.  It's more for anyone who stumbles across this later they can quickly find the solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.