Hi,
is it possible to use a web control to make a page go back to the previous page.
I've seen you can do it with javascript history.back() but was wondering if it's possible in VB code.
Thanks
Nick
Printable View
Hi,
is it possible to use a web control to make a page go back to the previous page.
I've seen you can do it with javascript history.back() but was wondering if it's possible in VB code.
Thanks
Nick
I just threw this together and did not test it, but I *think* it should work. If not, I'm sure it will be just a minor adjustment ;)
Code:using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace ServerControls {
public class BackButton : HtmlAnchor
{
public BackButton() {
InnerText = "Return To Previous Page";
if (HttpContext.Current.Request.UrlReferrer != null) {
HRef = HttpContext.Current.Request.UrlReferrer.ToString();
}
}
}
}
Your code is good, but only for one 'Back'. If used again, it will return to the last page, in effect, bouncing between the two pages.
It also will not go anywhere if the user arrived at your web page from a bookmark or typed URL.
Usually, I just:
Response.Write("<script>history.back()</script>")
hi lord_rat,
thought it was gonna work but only seems to refresh the page i'm already on.
Nick
try window.location.go(-1)
If that still does not work, I'll have to look it up ;).