Results 1 to 11 of 11

Thread: Redirect a user back to the page they came from

  1. #1

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    Redirect a user back to the page they came from

    How do I redirect a user back to the page they came from?

    On my aspx page, I have a cancel button. If the user clicks it, I want to send the user back to the page that they navigated from. Can I do this with the Response.Redirect?

  2. #2
    Lively Member
    Join Date
    Nov 2001
    Location
    Dallas
    Posts
    73
    Yes,

    You can just use: response.redirect("your_page.aspx")

    Kenny

  3. #3

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I know that, but I am not sure which page the user came from. The user could have came from any number of the pages.

  4. #4
    Member Ooogaleee's Avatar
    Join Date
    Nov 2002
    Location
    Jacksonville, FL
    Posts
    52

    Return trip

    Try to set the original page as a session variable before you redirect. That way you can use it in the second page. Try something like this -


    On the first page:

    Session("fromWhere")="firstPage.aspx"
    Response.Redirect("secondPage.aspx")


    On secondPage.aspx:

    Hyperlink1.NavigateUrl = Session("fromWhere")


    Simple enough, eh? Let us know if it works ok.

    Ooogs

  5. #5

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I was trying not to use session variables if I can help it. I want to keep the performance as fast as possible without tasking the server too much. I heard using session variables can eat away at the server if you have a lot of sessions and their variables being managed at one time.

    I will go that route if I have to though, thanks for the input. If anyone else has some other methods, they would be appreciated also.

  6. #6
    Lively Member
    Join Date
    Nov 2001
    Location
    Dallas
    Posts
    73
    You can store the user in hidden fields and then just use the same idea as above.

  7. #7
    New Member
    Join Date
    Dec 2002
    Posts
    4
    Response.Redirect(Request.UrlReferrer.PathAndQuery)


    - Justin_

  8. #8

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Awesome! Thanks a lot, that is what I was looking for.

  9. #9
    Member Ooogaleee's Avatar
    Join Date
    Nov 2002
    Location
    Jacksonville, FL
    Posts
    52

    UrlReferrer

    Does the:

    Response.Redirect(Request.UrlReferrer.PathAndQuery)

    need to be wrapped in a "If is NotPostBack Then" loop? Just curious as I was unsucessfull using it.

    Thanks...Ooogs

  10. #10

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I haven't had the chance to try it yet, hope it works...
    If you figure it out, post it here.

    I found this on the MSDN Library site:
    http://msdn.microsoft.com/library/de...errertopic.asp
    Last edited by hellswraith; Dec 30th, 2002 at 01:04 PM.

  11. #11
    New Member
    Join Date
    Dec 2002
    Posts
    4
    Put in the Page_Load method:

    Dim refHost As String = Request.UrlReferrer.Host

    If NOT Page.IsPostBack AND (refHost = Request.Url.Host) Then
    'The user came from a place on your website
    Response.Redirect(Request.UrlReferrer.PathAndQuery)
    Else
    If NOT refHost = Request.Url.Host Then
    'The user did not come from your website
    Else
    'The page was posted back
    End If
    End If


    - Justin_

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width