|
-
Dec 27th, 2002, 11:59 AM
#1
Thread Starter
PowerPoster
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?
-
Dec 27th, 2002, 12:03 PM
#2
Lively Member
Yes,
You can just use: response.redirect("your_page.aspx")
Kenny
-
Dec 27th, 2002, 12:05 PM
#3
Thread Starter
PowerPoster
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.
-
Dec 27th, 2002, 12:54 PM
#4
Member
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
-
Dec 27th, 2002, 01:22 PM
#5
Thread Starter
PowerPoster
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.
-
Dec 27th, 2002, 01:52 PM
#6
Lively Member
You can store the user in hidden fields and then just use the same idea as above.
-
Dec 30th, 2002, 03:53 AM
#7
New Member
Response.Redirect(Request.UrlReferrer.PathAndQuery)
- Justin_
-
Dec 30th, 2002, 12:32 PM
#8
Thread Starter
PowerPoster
Awesome! Thanks a lot, that is what I was looking for.
-
Dec 30th, 2002, 12:50 PM
#9
Member
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
-
Dec 30th, 2002, 01:01 PM
#10
Thread Starter
PowerPoster
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.
-
Dec 30th, 2002, 01:01 PM
#11
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|