11.3.6- Using the ASP Content Linker to Generate a Table of Contents
by NT Community Manager.
|
| << 11.3.5- Using the Content Linker with Home and End Hyperlinks | Chapter11 | 11.4.0- The Browser Capabilities Component >> |
Using the ASP Content Linker to Generate a
Table of Contents
Nowwe have some very clever hyperlinks for jumping to the nextand previous pages, as well as to the first and last pages. Best of all, duringmaintenance of the site we will never have to go into the actual pages holdingthose hyperlinks. All we have to do is open the index file in NotePad andreorder, delete or add pages. If you are writing ASP pages on contract, you cancharge your clients more for writing such programmer-friendly code. Inaddition, if you write ASP as part of a salaried job, you can ask your boss fora raise. Before you do that, however, let's cover another trick so you can askyour boss for a double increase in salary grade.
As long as we have the indexfile made up, what else could we do with it? Well, we could use thatinformation to make a hyperlinked table of contents for the tour of newproducts. We will create a loop that reads the first URL and description out ofthe index file and writes it as a hyperlink on the page, then puts in a <BR> (line break)tag, and then repeats these steps for each URL in the index file. Since we caneasily find out how many URL lines exist in the IndexFile with the GetListCount, we will use the For…Next syntax here.
A Solution for a Table of Contents based on an Index File
We will create a separate table of contents page, so no needto make any changes to our existing .asp files orthe index file.
Try It Out – A Basic Table of Contents Page
1. Open your editor, type in the following code and save in the BegASPfiles folderwith the file name cl-TOC.asp.
<%Option Explicit%>
<HTML>
<HEAD>
<TITLE>Tour of Products TOC</TITLE>
</HEAD>
<BODY>
<P>Tour of New Products - Table ofContents</P>
<%
Dim MyCurrentURL
Dim MyCurrentDescription
Dim MyListCount
Dim objNL
Dim URLCounter
SetobjNL=Server.CreateObject("MSWC.NextLink")
MyListCount =objNL.GetListCount("CL-NewProductsTour.txt")
For URLcounter = 1 To MyListCount
MyCurrentURL =objNL.GetNthURL("CL-NewProductsTour.txt", URLcounter)
MyCurrentDescription= objNL.GetNthDescription("CL-NewProductsTour.txt", URLcounter)
Response.Write "<A HREF='" &MyCurrentURL & "'>" & MyCurrentDescription &"</A>"
Response.Write "<BR>"
Next
%>
</BODY>
</HTML>
2. Fireup your browser, and at the address line type the URL http://my_server_name/BegASPFiles/cl-TOC.asp.
|
|
How It Works
First, we must set up aninstance of the Content Linker:
Set objNL =Server.CreateObject("MSWC.NextLink")
MyLastCount =objNL.GetListCount("CL-NewProductsTour.txt")
The instance is called objNL. We then store thetotal number of URL lines in the index file, in the variable MyLastCount:
MyLastCount =objNL.GetListCount("CL-NewProductsTour.txt")
Now we are ready to loop. Ourloop will iterate once for each of the values between 1 and MyLastCount inclusive:
For URLcounter =1 To MyLastCount
Within each iteration of the loop, we give the value of URLcounter to the method getNthURL to acquire the URL and descriptioncorresponding to the value of URLcounter. Thatdata is deposited in the two variables:
MyCurrentURL = objNL.GetNthURL("CL-NewProductsTour.txt",URLcounter)
MyCurrentDescription= objNL.GetNthDescription("CL-NewProductsTour.txt", URLcounter)
Then, we use Response.Write tocreate hyperlinks for each page in the tour. Remember that we are in the middleof ASP code here, not HTML. Therefore, we need to have ASP actually write outthe four characters"<BR>" to the page that HTML will send outto the browser. As you can see, we do that using the Response.Writemethod:
Response.Write "<A HREF='" &MyCurrentURL & "'>"
Response.Write MyCurrentDescription &"</A>"
Response.Write "<BR>"
Finally, we close off the loop with the Next keyword.
| << 11.3.5- Using the Content Linker with Home and End Hyperlinks | Chapter11 | 11.4.0- The Browser Capabilities Component >> |

RSS


