Hi, lets say that i have 3 pages, (origin1.aspx)/(origin2.aspx)/(destination.aspx), and i have a control which represents back button, its functionality is to get from which page it has been called. and once clicked redirects back to the original caller page, i have searched the web, and found many great and simple ideas, such as queryString, and sessions, but unfortunatly i must not use any of them, so any help ?
added link for you, hope you don't mind :)
Russ Cam
2009-10-26 11:18:53
If you go back a page, won't the referer now be pointing to the page you just came from, and would you not be redirecting yourself in circles?
Cory Larson
2009-10-26 11:19:35
@Cory - yes, which is why usually application "back" logic should be done with something capable of maintaining state, such as, well, query strings or sessions. But since the OP is ruling that out, there are very limited other options, and they have their flaws.
Amber
2009-10-26 11:23:38
Thx for help String path = uri.ToString(); return path; }
Saeedouv
2009-10-26 11:37:16
+1
A:
You could use a bit of JavaScript:
<asp:button id="m_BackButton" runat="server" onclientclick="goBack()" />
<script type="text/javascript">
function goBack(){
history.go(-1);
}
</script>
Zhaph - Ben Duguid
2009-10-26 11:24:47
Of course, this will only work if you don't want to pass information back to whatever page you're sending the user back to. But if all you want is to emulate the Back button in the browser, this is a good option. (However, if that's all you want to do, why not just let the user use their Back button?)
Amber
2009-10-26 11:30:50
:), u r right, but when it comes to requirements, even thought they can use back button instead, but finally it is required in that asp button way
Saeedouv
2009-10-26 11:47:22
instead of runat="server", it must be HTML button to take the javascript back effect
Saeedouv
2009-10-28 18:38:00
A:
You could go all clients side with javascript, but if you need to go to the server:
I don't think it is realy pretty but it gets the job done. Also gives you a lot of power.
First in the master page we have code like this so set the page name in a session
if (!IsPostBack)
{
if (Request.UrlReferrer != null && Request.UrlReferrer.AbsoluteUri != null)
{
Session.Add("UrlReferrer", Request.UrlReferrer.AbsoluteUri);
}
}
Then we have a ashx backhandler with simple code like this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication1
{
/// <summary>
/// Summary description for Backhandler
/// </summary>
public class Backhandler : IHttpHandler
{
private const string DEFAULTPAGE = "MyDdefaultreturnpage.aspx";
public void ProcessRequest(HttpContext context)
{
string previousPage = context.Session["UrlReferrer"] as String ?? DEFAULTPAGE;
context.Response.Redirect(previousPage);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
All the backbuttons in the app can do a redirect to the backhandler.ashx files. Yuo could even put this in your css.
Hope this helps.
KeesDijk
2009-10-26 11:34:15