Solved

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

Posted on 2008-10-17
4
1,155 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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