Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

go to url of page I just came from

Posted on 2013-01-11
2
Medium Priority
?
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

721 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