Solved

go to url of page I just came from

Posted on 2013-01-11
2
207 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now