locked
Creating a "back" link RRS feed

  • Question

  • Hi again!  This time I need to create a link where, when clicked, the user is returned to the previous page.  Now, I know how to put a hyperlink in to link to the page but the page I want to link to is a results of a database search page so that the results are still there.  If I just put in a hyperlink to the page in question then is is blank as it has no results to show.

    I am using c# and aspx pages.

    Hope all that makes sense!

    Sunday, August 22, 2010 10:29 AM

Answers

All replies

  • <a href="javascript:window.history.go(-1)">Back</a>


    Ron Symonds
    Microsoft MVP (Expression Web)

    www.rxs-enterprises.org/fp
    Sunday, August 22, 2010 10:51 AM

  • Here's a "server side" way to do that, if you are using either asp.net.

    <%Dim backpage As String =Request.ServerVariables("HTTP_REFERER") %>
          <%if backpage <> "" then%>
              <a href="<%=backpage%>">Go back to previous page</a>
              <%else%>
              <a href="staticlink.aspx">Go to home page</a>      
          <%End if%>
    

    Here is a test page in action. Once there, click on the link to get to the page that has the above code in it:

    http://www.tribute2abeautifulperson.com/default11.aspx

    Note: Even though this is server side, and should be 100% robust, in past years I have seen where certain versions of Norton Securities blocked the servervariables call. I know strange but true. At any rate, that is why I include a static link as a just in case.

    Rick
    www.allureiw.com

     

     

     


    rickidoo
    Sunday, August 22, 2010 11:34 AM
  • Brilliant thanks, you guys on here are the best!
    Sunday, August 22, 2010 1:54 PM
  • FWIW, I expect users to know how to use the back button in their browser and to use it if they need to do so.

    I really see no reason to clutter up my websites repeating browser functionality such as back buttons and text resizing.


    MS MVP Expression Tutorials & Help http://by-expression.com
    Sunday, August 22, 2010 3:40 PM
  • Plus coding a back button with JS can be buggy.  This was an idea that designers/developers threw out 10 years ago...
    --
    Chris Hanscom - Microsoft MVP
    On Facebook | On Twitter | Resource Center | Veign's Blog | Web Development Help

    Get a Complete Website Analysis by Veign
    Sunday, August 22, 2010 4:05 PM