Solved

ASP.NET back to previous page button?

Posted on 2009-07-01
10
857 Views
Last Modified: 2013-12-17
Hi,

Is it possible to create an asp.net button on a web page that will allow a user to navigate back to the previous page?

Thanks.
0
Comment
Question by:Shepwedd
  • 5
  • 5
10 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 24755060
In the Page_Load try this:
if (!Page.IsPostBack && Page.Request.UrlReferrer!=null)
        {  
            btnPrevious.PostBackUrl = Page.Request.UrlReferrer.AbsolutePath;
        }
0
 

Author Comment

by:Shepwedd
ID: 24755587
I added the attached code as suggested but I get the error: "Operator '=' incompatible with operand types 'Int32' and 'Object' "

The ID of my button on the frontend is "BackButton"

Thanks.
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack && Page.Request.UrlReferrer != null)
        {
            BackButton.PostBackUrl = Page.Request.UrlReferrer.AbsolutePath;
        }
    }

Open in new window

0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24755652
Is the error due to that code...not sure...it could be for some other code in your page.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Shepwedd
ID: 24755779
So the above code is correct?

The page I am trying to navigate back to is populated through a query string variable (http://www.page.aspx?variable=1), could this be causing an issue? I can press the back button on the browser to navigate back but I was hoping to create a button on the page to do the same for friendlier navigation.

Thanks.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24755950
The querystring parameter is lost as.
How are you navigating to Page2 from page1?

Page1 --> Page2-->Page1
I would suggest you to store the querystring parameter tht Page1 takes in Session before your navigate to Page2. Upon return to Page1 i.e. page1 Load ...check for querystring param...if it is null get the value from Session...
Now you have to be careful ...if Session is null then you should take appropriate step.

Or you can do is pass the querystring param to Page2...
Retrieve it on page2...
append it to Page.Request.UrlReferrer.AbsolutePath and then assign it to PostBackUrl property
0
 

Author Comment

by:Shepwedd
ID: 24761299
I am navigating to page 2 from page 1 through the below link:

<a href="applicantInterviewInterviewers.aspx?interviewid=<%#Eval("InterviewID")%>"  target="popup" onclick="return wopen_popup(this.href,this.target, 900, 500)">Interiewers</a>

I do I save a parameter in session? Code would be appreciated.

Thanks.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24764192
Looks you are opening that page in new window....and then you want to go back to Parent page...won't that keep two pages open?

Here is something you can do...on Page2 Load:

 if (!Page.IsPostBack && Page.Request.UrlReferrer!=null)
        {
            string queryparam = String.Empty;
            string url = Page.Request.UrlReferrer.AbsolutePath;
            if(Page.ClientQueryString!=null)
            {  /* Another way to create postBackUrl
                queryparam = Request.QueryString["interviewid"].ToString();
                url = url + "?interviewid="+queryparam;
                 */
                url = url + "?"+ Page.ClientQueryString;
            }
            Button1.PostBackUrl = url;
        }

0
 

Author Comment

by:Shepwedd
ID: 24764798
Page 1 is my parent page.
Page 2 is a popup window
Page 3 is a popup window

I want to be able to go back to page 2 from page 3 by means of a button.
0
 

Author Comment

by:Shepwedd
ID: 24764834
With your suggested code I get the error: "Operator '=' incompatible with operand types 'Int32' and 'Object'"??

Thanks.
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 24765084
Alrite Page3 is something addition to what I was considering...
Page1 to-->Page 2 to--> Page3 to--> Page 2
If this is the case then:
In Page 2 Load:
if (!Page.IsPostBack && Page.ClientQueryString != null)
        { //What you are doing here is storing the QueryString in Session so you can retrieve in in Page3
           //Append it to PostBackUrl of btnPrevious on Page3 Load
                Session["interviewid"] = Page.ClientQueryString.ToString();
        }


Page 3 Load:
if (!Page.IsPostBack && Page.Request.UrlReferrer!=null )
        {
            string url = Page.Request.UrlReferrer.AbsolutePath;
            if (Session["interviewid"] != null)
            {    url = url + "?" + Session["interviewid"].ToString();
            }
            btnPrevious.PostBackUrl = url;
        }

Hope this works as per requirement.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sort GridView by ID Descending 1 17
bound data table problem 2 33
C# Service FileSystemwatcher isse 9 27
TFS 2015 Access denied. 1 15
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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