?
Solved

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

Posted on 2008-10-17
4
Medium Priority
?
1,159 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
[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
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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

770 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