Reputation: 956
On a .net site, is there an easy way to send someone back to the last page they were on before they posted back a form on the current page without some sort of overwrought breadcrumb system? I know that sounds a bit confusing, but lets say you're on Page1.aspx. You go to Page2.aspx, which has a web form. You fill out the web form which posts back to itself. After the postback, I want to send them back to whatever page they were on first, in this case : Page1.aspx. Page1.aspx is obviously variable.
I started playing with some javascript using history.go(), but I wasn't able to get it to work properly. Any suggestions?
Upvotes: 1
Views: 2615
Reputation: 14645
You could pass the referrer (Page1.aspx) to Page2.aspx. Page2.aspx then uses a hidden input-field, containing the referrer.
When the visitor submits the form from Page2 (to itself), the form-handler then receives the referrer and could set it as a http-equiv="refresh"
in the resulting page.
<html>
<head>
<title>Form Result</title>
<meta http-equiv="refresh" content="5;URL='Page1.aspx'" />
</head>
<body>
<p>Thank you for your input, you will automatically return to
<a href="Page1.aspx/">the previous page in 5 seconds.</a>.</p>
</body>
</html>
By changing the timeout to more than 0 seconds the user can still read the result before he is automatically sent back to the page he came from.
Hope this helps!
Upvotes: 0
Reputation: 66641
You can send the page that must return as a url parameter, just like login module do.
Eg, you go to the page2.aspx
with this url page2.aspx?RetPage=Page1.aspx
and when you finish with the page2, you get the RetPage
and redirect to whatever value you have set there.
Upvotes: 0
Reputation: 15253
Use the Request.UrlReferrer Property as described here:
Navigate to Previous Page in ASP.NET(Request.UrlReferrer)
Upvotes: 1