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

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

lgallionAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vs1784Commented:
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
lgallionAuthor Commented:
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
vs1784Commented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

lgallionAuthor Commented:
vs1784 I think I follow you but could you give a short example of that?
0
vs1784Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lgallionAuthor Commented:
Thank you very much for the quick response and example.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.