• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

go to url of page I just came from

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)
Tom Knowlton
Tom Knowlton
1 Solution
Guru JiCommented:
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)

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)

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


Hope that helped you
Tom KnowltonWeb developerAuthor Commented:
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();
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.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now