11.3.3- Adding Descriptions and Previous to Our Link
by NT Community Manager.
|
| << 11.3.2- ASP Pages that Use Content Linker to Hyperlink to the Next Page | Chapter11 | 11.3.4- Using the Content Linker and Control Structures to Display Only Appropriate Links >> |
Adding Descriptions and Previous toOur Link
When wecreated the index file, we saw that it was organized into three columns of datawith a row for each URL in the progression. The first column contains the nameof the URL, the second column contains a description, and the third column heldcomments about the page.
We can adapt the previousexample, so that the user can click on the description rather than Previous or Next. In fact, we willeven embellish that description with some hard-coded text to give us a dynamichyperlink label. Hence, when the user clicks on the hyperlink text, they knowexactly what they are going to learn about in advance.
Furthermore, we can improvethis tour to accommodate a viewer that might want to go back to a product page.With a bit of copying and syntax "changing" we can add a PreviousPage hyperlink.
Try It Out – Using Content Linker with Descriptions and Previous
Since all of the navigation code is contained in one file wedo not have to edit the product pages. We just modify CL-Navigation.asp.
I suggest that prior to these steps you save your oldnavigation file as
CL-Navigation01.asp. That way, if you ever needto review it you have it in its simplest form. Remember that the product pagesalways include CL-Navigation.asp, so whicheverversion has that name will be the one in effect.If you are downloading files from the Wrox website, the file below will be CL-Navigator02.asp; renameit to CL-Navigation.asp.
1. With your editor of choice, open up CL-Navigation.asp, make the followingchanges, and save the file with the same name.
<%
Response.Write "<HR>"
Dim MyPageNext
Dim MyPagePrevious
Dim MyDescriptNext
Dim MyDescriptPrevious
Dim objNL
Set objNL =Server.Createobject("MSWC.NextLink")
MyPageNext =objNL.GetNextURL("CL-NewProductsTour.txt")
MyPagePrevious =objNL.GetPreviousURL("CL-NewProductsTour.txt")
MyDescriptNext =objNL.GetNextDescription("CL-NewProductsTour.txt")
MyDescriptPrevious =objNL.GetPreviousDescription("CL-NewProductsTour.txt")
Response.Write "Next: <A HREF='" &MyPageNext & "'>" &_
MyDescriptNext & "</A>  "
Response.Write "Back: <A HREF='" &MyPagePrevious & "'>" &_
MyDescriptPrevious &"</A>"
%>
2. Open up your browser of choice. At the address line, type inthe URL http://my_server_name/BegASP/CL-Hat.asp.Click on the hyperlinks to move back and forward through the tour.
|
|
How It Works
In this example, we have added to the navigation file a few lines thatutilize new methods – ones that can get the description of a page and can getthe information for the previous page. Note that even though we have anadditional method, we can still use the same instance of the NextLink object. Inother words, there's no need for a second CreateObject statement. Here's the statement, for a given page,that calls the description of the next page in the tour:
MyDescriptNext =objNL.GetNextDescription("CL-NewProductsTour.txt")
The description is containedin the variable MyDescriptNext. Then we use this to make the hyperlink even morecomplex, as follows:
Response.Write "Next: <A HREF='" &MyPageNext & "'>" &_
MyDescriptNext & "</A>  "
This looks similar to our previous link, but you should nownotice that we use two variables within our link. We start by building up thestatement as we did before, using single quotes to enclose the HREF and doublequotes to enclose any HTML and text. We insert the target variable (which, ifyou remember, holds the URL of the next item in our index) between the two HTMLblocks that end and begin with the single quote, enabling the variable to beused like a standard link. Instead of inserting the text saying "Clickhere for next item", this time we call up the description of the next itemin the index with the MyDescriptNext variable. Wethen close off the tag and insert a couple of spaces. Again, try viewing thesource to our page in your browser, to see the HTML.
Keep in mind that the URL of the HREF needs double quotes,but the hyperlinked text does not
We then do exactly the same style of procedure to produce alink to the previous item in our index:
MyDescriptPrev =objNL.GetPreviousDescription("NewProductsTour.txt")
This line calls up the description of the previous page onthe tour. We then use this variable to insert the description of the file intothe link:
Response.Write "Back: <A HREF='" &MyPagePrevious & "'>" &_
MyDescriptPrevious &"</A>"
The second improvement, adding the previous links is theexact same as the next link except that we use the methods GetPreviousURL and GetPreviousDescription. Be careful not to accidentallytype GetPrevURL, a very common mistake.
| << 11.3.2- ASP Pages that Use Content Linker to Hyperlink to the Next Page | Chapter11 | 11.3.4- Using the Content Linker and Control Structures to Display Only Appropriate Links >> |

RSS


