Link to home
Start Free TrialLog in
Avatar of mcexario
mcexario

asked on

How to go forward or go backward in ASP with an image?

I have a simple link.asp page that has a simple arrow pointing left and an arrow pointing right  Below is what the ASP code for these images are:

<img src="../images/Layers_16.gif" border="0" width="26" height="26">

What I'm trying to do is to add the ocde to go backwards or go forward a web page but I'm unsure what code to use to redirect the image when it is click to go forward or backward.

Thanks,
Mark
Avatar of rdivilbiss
rdivilbiss
Flag of United States of America image

<a href="<%request.servervariables("HTTP_REFERER")%>"><img src="../images/Layers_16.gif" border="0" width="26" height="26"></a>

will take you back a page assuming you came from another page and didn't enter this page directly from a bookmark.

To go forward a page, you need to know what the page name is....

<a href="REPLACE-WITH-THE-NAME-OF-THE-NEXT-PAGE.htm"><img src="../images/Layers_16.gif" border="0" width="26" height="26"></a>




Avatar of rockmansattic
rockmansattic

Similar in Javascript

<a href="javascript:history.go(-1)"><img src="../images/Layers_16.gif" border="0" width="26" height="26"></a>

AND

<a href="javascript:history.go(+1)"><img src="../images/Layers_16.gif" border="0" width="26" height="26"></a>

Of course if the user has JS turned off, SOL.

Rockman
>>in ASP
Avatar of mcexario

ASKER

I tried this -

<a href=<% request.servervariables("HTTP_REFERER")%>"><img src="../images/Layers_18.gif" border="0" width="26" height="26"></a>

and it doesn't work and I get the a ' "> ' in front of the image.  It looks like ASP can not interpert the href using request.servervariables.  When I hit the image I get this in the URL - http://localhost/sigtech/<%

Any ideas?
SOLUTION
Avatar of rdivilbiss
rdivilbiss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry for the typo's, but it still doesn't work.  Here's my corrected code -
<a href="<% request.servervariables('HTTP_REFERER') %>"><img src="../images/Layers_18.gif" border="0" width="26" height="26"></a>

I originally had double quotes around the HTT_REFERER enum but it was taken as the second double quote for the href.

Now I get this when I hit the image on the URL -

http://localhost/sigtech/<%%20request.servervariables('HTTP_REFERER')%20%>

Please note that I've tried the <%= and the <% (as above) and I get the same behavior with both.

Thanks,
Mark
Try using Response.Write

This works fine with me:

<a href='<% Response.Write(Request.servervariables("HTTP_REFERER")) %>'><img src="../images/Layers_18.gif" border="0" width="26" height="26"></a>


mem99999,

<%=request.servervariables("HTTP_REFERER")%>, previously posted, is using response.write.
---^

= is response.write.
These still do not work.  Maybe there something in my IE settings but this is what I get for both of the above recommendations -

Using Response.Write---------------------------------
<a href='<%= Response.Write(Request.servervariables("HTTP_REFERER")) %>'><img src="../images/Layers_18.gif" border="0" width="26" height="26"></a>
URL = http://localhost/sigtech/<%=%20Response.Write(Request.servervariables("HTTP_REFERER"))%20%>

Using %= ---------------------------------------------------
<a href=<%=request.servervariables("HTTP_REFERER")%> <img src="../images/Layers_18.gif" border="0" width="26" height="26"></a>
URL = http://localhost/sigtech/<%=request.servervariables("HTTP_REFERER")%

It looks the URL being created never executes the inline code.  Is that correct?

Thanks,
Mark
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
copy what I posted without the equal sign '='

i.e.

<a href='<% Response.Write(Request.servervariables("HTTP_REFERER")) %>'><img src="../images/Layers_18.gif" border="0" width="26" height="26"></a>

* Are you sure your server is serving ASP pages correctly?

e.g. try an asp page with only: <% Response.Write("Hello World") %>
Thanks, chaning to .asp worked.  Now that I include this page to all of my web pages is there a problem with all my pages ending in .asp as oppose to .htm?

Also, now I can go backwards how would I go forward.  Is there a similar request.servervariables parameter like HTTP_REFERER.  I couldn't find anything.

Thanks,
Mark
>Thanks, chaning to .asp worked.  Now that I include this page to all of my web pages is there a problem with all my pages ending in .asp as oppose to .htm?

None.

>Also, now I can go backwards how would I go forward.  Is there a similar request.servervariables parameter like HTTP_REFERER.  I couldn't find anything.

There is none. That would require the server to be clarivoiant and know what the next page is, which of course would be more work than hard coding the <a href="...">xxx</a> tag.

However, if your pages were named in a specific manner, say page1.asp, page2.asp, etc. then you could write some ASP to create the next page link so you can use a simple include for each page.

<%
page = request.servervariables("SCRIPT_NAME")
pageno = Mid(page,InStr(page,"page")+4,99)
pageno = CInt(Left(page,InStr(page,".asp")-1))

nextpage = "page" & pageno+1 & ".asp"
%>


<a href="<%=nextpage%>">Next</a>




%>