Solved

go to url of page I just came from

Posted on 2013-01-11
2
234 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:knowlton
2 Comments
 
LVL 11

Accepted Solution

by:
Guru Ji earned 500 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: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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

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…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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