|
-
Oct 15th, 2003, 04:15 AM
#1
Thread Starter
Fanatic Member
back button
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
-
Oct 15th, 2003, 08:02 AM
#2
PowerPoster
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();
}
}
}
}
-
Oct 15th, 2003, 03:27 PM
#3
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>")
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Oct 16th, 2003, 03:01 AM
#4
Thread Starter
Fanatic Member
hi lord_rat,
thought it was gonna work but only seems to refresh the page i'm already on.
Nick
-
Oct 20th, 2003, 01:08 PM
#5
try window.location.go(-1)
If that still does not work, I'll have to look it up .
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
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
|