Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ASP .Net back button

Posted on 2009-02-12
16
Medium Priority
?
515 Views
Last Modified: 2013-11-07
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

0
Comment
Question by:Kyle Abrahams
  • 8
  • 8
16 Comments
 
LVL 16

Expert Comment

by:sunithnair
ID: 23624067
Please try this

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

Open in new window

0
 
LVL 16

Expert Comment

by:sunithnair
ID: 23624085
Try this link for more information http://docs.sun.com/source/816-6408-10/history.htm
0
 
LVL 41

Author Comment

by:Kyle Abrahams
ID: 23624125
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 41

Author Comment

by:Kyle Abrahams
ID: 23624179
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
 
LVL 16

Expert Comment

by:sunithnair
ID: 23624269
How many pages involved? 1st Page (Param page) and 2nd Page (Report page) Is there are other page in the middle?
0
 
LVL 41

Author Comment

by:Kyle Abrahams
ID: 23624777
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
 
LVL 16

Expert Comment

by:sunithnair
ID: 23625843
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
 
LVL 16

Expert Comment

by:sunithnair
ID: 23625852
I am not sure if there is an syntax error in the above code or not
0
 
LVL 41

Author Comment

by:Kyle Abrahams
ID: 23626018
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
 
LVL 16

Expert Comment

by:sunithnair
ID: 23626682
instead of server.transfer why dont you try and submit the form if that solves the problem?
0
 
LVL 41

Author Comment

by:Kyle Abrahams
ID: 23632678
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
 
LVL 16

Assisted Solution

by:sunithnair
sunithnair earned 2000 total points
ID: 23633264
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
 
LVL 41

Author Comment

by:Kyle Abrahams
ID: 23634327
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
 
LVL 41

Accepted Solution

by:
Kyle Abrahams earned 0 total points
ID: 23634503
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
 
LVL 16

Expert Comment

by:sunithnair
ID: 23635192
So is the solution working now?
0
 
LVL 41

Author Comment

by:Kyle Abrahams
ID: 23635591
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

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question