Forum Moderators: open

Message Too Old, No Replies

Can I use ASP to apply styles to menu items?

I want to hide links based on what page the user is viewing.

         

katana_one

8:43 pm on Sep 20, 2004 (gmt 0)

10+ Year Member



My site currently uses ASP file.include statements for things like primary navigation menu and page footers. My question is: can I use ASP to assign a CSS style which will "hide" the link for the page the user is currently viewing? Basically, if the user is viewing the page "index.asp" I want to hide the "Home" page link. If they then go to "contact.asp" then I want to hide the "Contact Us" link instead.

I'm still new to ASP and I'm not sure if this will be more trouble than it is worth.

Thanks in advance for any advice.

mattglet

9:53 pm on Sep 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In your include file, you have to check to see what page the user is on.

There are a bunch of things you can use to accomplish this:
Request.ServerVariables("SCRIPT_NAME")
Request.ServerVariables("URL")
Request.ServerVariables("PATH_INFO")

I use SCRIPT_NAME as my preference, they all essentially do the same thing.

If the user is on that page, then don't show the link:

<%
if not Request.ServerVariables("SCRIPT_NAME") = "/contact.asp" then%>
<a href = "contact.asp"><img src = "contact_image.gif"></a>
<%
end if%>

Do that for each of your nav links, and you should be all set.

katana_one

3:35 pm on Sep 21, 2004 (gmt 0)

10+ Year Member



Thanks, mattglet!

That was much easier than I thought it would be. After trying it out, I decided that I wanted to style the link for the current page differently instead of hiding it altogether. Your suggestion was simple enough that I was able to rewrite it to add a CSS class to the link instead of hiding it.