Clicking the Back button in ASPX and VB

Discussion in 'ASP.NET / ASP.NET Core' started by bennettw, Sep 12, 2003.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I'm coding in ASPX and VB and trying to go back to the last web page the user accessed. I found the processModelInfo class but it is not enabled on the discountAPS server. Does any know anyother way to go back?
     
  2. Thanks for responding. I'm trying to write in code the equivalent of clicking the Back button in my browser. I want to have a button on my web page that will take the user to the previous site visited. In Java script there was the window.back (or window.history). Is there the same in .Net running IIS 6?

    BB
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    Not quite sure what you want to do.

    Can you elaborate on what you mean by "going back"?

    quote:Originally posted by bennettw

    I'm coding in ASPX and VB and trying to go back to the last web page the user accessed. I found the processModelInfo class but it is not enabled on the discountAPS server. Does any know anyother way to go back?

    </blockquote id="quote"></font id="quote">
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    i don't think you can do this on the server side. THe web server has no knowledge of where the client visited before.

    the only way you can do this is through client side scripting, like javascript

    quote:Originally posted by bennettw

    Thanks for responding. I'm trying to write in code the equivalent of clicking the Back button in my browser. I want to have a button on my web page that will take the user to the previous site visited. In Java script there was the window.back (or window.history). Is there the same in .Net running IIS 6?

    BB
    </blockquote id="quote"></font id="quote">
     
  5. If You want to use java script here it is.

    <A href="javascript:history.back()">Go back
     
  6. bennettw,

    I believe you can get the page the user came from, from the ServerVariables collection

    Try:
    Request.ServerVariables("HTTP_REFERER")

    I believe it holds the whole url where the user came from, but it may only hold the domain name. I don't remember off the top of my head.

    Hope that helps.

    Cheers,
    bajdev
     
  7. It is possible to do it server-side.

    You need to capture the address of the calling page and persist it to survive postbacks. One example would be to use a hidden label. You put the following line in the Page_Load:

    lblUrlReferrer.Text = Request.UrlReferrer.AbsolutePath.ToString

    Note: It would be wise to put a try/catch around this line just in case there is no referrer page.


    Next, you add a link button or form button to the page, then put the following line in the button's click event:

    Response.Redirect(lblUrlReferrer.Text)


    Yes, this is a roundabout way of doing it, but sometimes the javascript back() method won't take you to the page where you want to be (depending on the postback and redirection activity).

    I hope this helps.


    Allan Sieker
    Eureka, MO
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page