Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

go to url of page I just came from

Posted on 2013-01-11
2
Medium Priority
?
247 Views
Last Modified: 2013-01-11
In asp.net c# how do I programmatically go back to the page I just came from?

On any page, how do I obtain the URL of the page?  (what is in the address bar)
0
Comment
Question by:Tom Knowlton
2 Comments
 
LVL 11

Accepted Solution

by:
Guru Ji earned 2000 total points
ID: 38768639
As your question is vague in terms of what url, so I will answer accordingly

If you know the page you came from then you can write a button click code to go to that particular page as follows

protected void Button1_Click(object sender, EventArgs e)
{
     Response.Redirect("Page2.aspx");
}

But if its going to be random pages like google, yahoo or anything then you can get the referrer of the page and redirect accordingly like below
// static variable
static string prevPage = String.Empty;
 
protected void Page_Load(object sender, EventArgs e)
{
     if( !IsPostBack )
     {
         prevPage = Request.UrlReferrer.ToString();
     }
 
 }
 
 protected void Button1_Click(object sender, EventArgs e)
 {
      Response.Redirect(prevPage);
 }


and In order to get URL from the address bar its just one line

Request.RawUrl.ToString();

Hope that helped you
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 38768724
This is what I meant, which I think you did answer above:

Page A:

            string thisPage = Request.UrlReferrer.ToString();
            Session["afa_parent"] = thisPage;
            Response.Redirect(***Page B url***);


Page B ( on click "cancel" ):

            string prevPage = Session["afa_parent"].ToString();
            Response.Redirect(prevPage);
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

885 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