Results 1 to 5 of 5

Thread: back button

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870

    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
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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();
    			}
    		}
    	}
    }

  3. #3
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    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)

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    hi lord_rat,

    thought it was gonna work but only seems to refresh the page i'm already on.

    Nick
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  5. #5
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    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
  •  



Click Here to Expand Forum to Full Width