?
Solved

Can Asp Hyperlink statement return user to previous page instead of fixed URL?

Posted on 2008-02-11
6
Medium Priority
?
728 Views
Last Modified: 2012-08-14
I am trying to edit an existing ASP script and would like the button defined below (see code) to not return to a fixed URL but instead to the http_referer (previous) page.  Is there any way to do this?

Thanks in advance
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="BodyText" NavigateUrl="../somedirectory/somepage.html" ImageUrl="~/images/Buttons/button_BackToShopping.gif">Back to Shopping</asp:HyperLink>

Open in new window

0
Comment
Question by:lgallion
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:vs1784
ID: 20868392
Try this
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="BodyText" NavigateUrl="javascript:history.go(-1);" ImageUrl="~/images/Buttons/button_BackToShopping.gif">Back to Shopping</asp:HyperLink>
 

Open in new window

0
 

Author Comment

by:lgallion
ID: 20868599
vs1784, thanks for your answer and it works, to a point.  Unfortunately the situation isn't as quite as simple as I described because the page this script is on is a shopping cart.  If you edit the items on the cart (for example) you can't simply go back a fixed number of pages to get to the refering page. Sorry I didn't think far enough ahead to anticipate this problem :-(
0
 
LVL 11

Expert Comment

by:vs1784
ID: 20868638
In that case you can set Navigate URL in page load event if its not postback.

So that it wont reset it in postback i.e. updating quantity and removing items.

Hope it helps.

Thanks
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:lgallion
ID: 20868710
vs1784 I think I follow you but could you give a short example of that?
0
 
LVL 11

Accepted Solution

by:
vs1784 earned 2000 total points
ID: 20868825
You can use below code

if(!IsPostBack)
{
     HyperLink1.NavigateURL = Context.Request.UrlReferrer.ToString();
}

However it is not necessary that Refferer will always return expected result so you might have to store the last page visited in session variable and use it.
0
 

Author Closing Comment

by:lgallion
ID: 31429878
Thank you very much for the quick response and example.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
These seven tips can help you create an extraordinary website, one that captivates audiences and has them wanting to return regularly for more. Keep reading to find out what your site is missing and what you need to add!
The viewer will learn how to count occurrences of each item in an array.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses
Course of the Month3 days, 19 hours left to enroll

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question