Solved

How to get the name of the calling page in ASP.NET?

Posted on 2008-10-17
4
1,152 Views
Last Modified: 2010-05-18
Hello - I have a "list" page, that works in conjunction with a "detail" page; the detail page has a link on it to "Return to list", with the following code executed on the Click:
      Response.Redirect("~/ProjectsList.aspx")

Now I have been asked to provide a second version of the list page; a given user will be using one or the other, depending on their access rights. (I am not using ASP.NET's navigation features; I did my own user access control.)

So now, from the detail page, I need to return to the version of the list page that they came from.

Can someone tell me the syntax (in ASP.NET v2.0, VB.NET) to test the name of the previous page? So I can do something like:

      If {calling page name = "ProjectsList1.aspx"} then
            Response.Redirect("~/ProjectsList1.aspx")
      Else
            Response.Redirect("~/ProjectsList2.aspx")
      End If      

Unless there is a smarter way to do this?

Thanks

0
Comment
Question by:mlagrange
4 Comments
 
LVL 6

Expert Comment

by:pwrBall
ID: 22745483
Request.UrlReferrer.ToString();
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22745531
You can try "Request.UrlReferrer" - this will give the url of the previous page

I am not sure if you would be able to get the name of the file.in below approach
but you can get the reference to the page that redirected to the current page from the property "PreviousPage"
eg.
PreviousPage.Form.Name will give you the name of the form in previous page

take a look at the properties available in "PreviousPage" and use the one suitable for you.


0
 
LVL 3

Accepted Solution

by:
JunkMan earned 500 total points
ID: 22746308
There are some issues with using HTTPReferer, some firewalls/antivirus block it from being sent. Thus you might have the odd user that is not able to return to the list. If you don't mind that the solution provided by TechTiger007 or pwrBall should work fine. But if you do I would suggest just sending the url of the list to the detail page and redirect back from that.
<a href="mydetailpage.aspx?ret_url=<%= Server.UrlEncode(Request.RawUrl) %>">view detail</a>
 
//and your return link would look like
 
 
<a href="<%= Server.UrlDecode(Request.QueryString["ret_url"]) %>">Return to list</a>

Open in new window

0
 

Author Comment

by:mlagrange
ID: 22747907
pwrBall - I checked the value in Request.UrlReferrer in the debugger; it was the detail page name

TechTiger007 - PreviousPage had no values in it at all

I think JunkMan's answer is the most practical for what I need at the moment

Thank you all for your responses
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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