ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!



Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

QUICK TIP:
Persistent Radio Buttons
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


Navigation Stars *

For all the great content we have on the site, one of the most popular questions we get has nothing to do with the content. Once people realize that we're using one template for the entire site, they inevitably ask: "How do you get the little star in the navigation bar to appear next to the name of the section the user is currently in?"

Well, the first step is determining where the user is. To do this we use the value of URL from the Request.ServerVariables collection. That gives us a absolute path without the server name like /samples/index.asp. From there we strip out just the first level directory name and use that as our locator.

From that information we know what directory the page the user has requested is in and because we've kept the site somewhat well organized, that takes care of the bulk of it since our directory structure closely resembles the logical structure of the site.

From there it's just a matter of some conditionals determining where to show the star.

Here's a simplified version of the code in case you actually want to try something similar on your site:

<%
Const STAR_HTML = "<FONT COLOR=""#FF0000""><B><CODE>*</CODE></B></FONT> "
Dim strSection
' Get full path
strSection = Request.ServerVariables("URL")
' Pull out first level directory.  Defaults to "home" if we're on the root
If InStr(2, strSection, "/", 1) = 0 Then
	strSection = "home"
Else
	strSection = Mid(strSection, 2, Instr(2, strSection, "/", 1) - 2)
End If
' Convert to lower case for ease of comparison
strSection = LCase(strSection)
%>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
 <TD><% If strSection = "home"    Then Response.Write STAR_HTML %></TD>
 <TD><A HREF="/index.asp">Home</A></TD>
</TR>
<TR>
 <TD><% If strSection = "news"    Then Response.Write STAR_HTML %></TD>
 <TD><A HREF="/news/index.asp">News</A></TD>
</TR>
<TR>
 <TD><% If strSection = "tips"    Then Response.Write STAR_HTML %></TD>
 <TD><A HREF="/tips/index.asp">Tips</A></TD>
</TR>
<TR>
 <TD><% If strSection = "samples" Then Response.Write STAR_HTML %></TD>
 <TD><A HREF="/samples/index.asp">Samples</A></TD>
</TR>
</TABLE>

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers