Page

11.3.5- Using the Content Linker with Home and End Hyperlinks

  by NT Community Manager.
Last Updated  by NT Community Manager.  

PublicCategorized as 11. Active Server Pages Components.

Not tagged.
<< 11.3.4- Using the Content Linker and Control Structures to Display Only Appropriate LinksChapter1111.3.6- Using the ASP Content Linker to Generate a Table of Contents >>

Using the Content Linker with Home and End Hyperlinks

Most modern computer users are accustomed to the idea of havingoptions for Homeand Endwhen in a series of steps. This probably comes from Microsoft Wizards, as muchas from well-designed web pages. The Content Linker gives you two more methods,GetNthURL and GetNthDescription. In these methods, Nth is the programmer's way of implying that a pagenumber is to be determined; for example the first page number is N=1. However, since ourWebmaster frequently adds and removes pages from the index file, we will neverbe sure what the last page number will be. Therefore, we can ask ASP to countthem at the moment it builds the page by using the method GetListCount. As yourecall from the previous example, this is done by the following line:

 

MyListCount =objNL.GetListCount("CL-NewProductsTour.txt")

We can then get the number ofthe last page, since we recognize that Nis equal to the current value of MyListCount. To use the GetNthURL method, we need to know how to tell the method thenumber that we want. This transfer of information is done by a second parameterafter the name of the index file separatedby a comma. For example, to get the URL of the first page we use:

 

MyFirstPage =objNL.GetNthURL("NewProductsTour.txt", 1)

 

And toget the URL of the last page we use our a variable as the second parameter:

 

MyEndPage =objNL.GetNthURL("NewProductsTour.txt", MyListCount)

Try It Out – Adding Home and End Links

1.    Openyour file CL-Navigation.asp(if you want, save the current version as
CL-Navigaton03.asp).To this file, add the following highlighted lines. If you are downloading thesefiles from the Wrox site, you can open CL-Navigation04.asp and rename this to CL-Navigation.asp whenyou run the example.

 

<%

  Response.Write "<HR>"

  Dim MyPageNext

  Dim MyPagePreviousious

  Dim MyDescriptNext

  Dim MyDescriptPrev

  Dim MyListCount

  Dim MyListIndex

  Dim MyFirstPage

  Dim MyLastPage

 

  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")

  MyListCount =objNL.GetListCount("CL-NewProductsTour.txt")

  MyListIndex =objNL.GetListIndex("CL-NewProductsTour.txt")

  MyFirstPage =objNL.GetNthURL("CL-NewProductsTour.txt",1)

  MyLastPage =objNL.GetNthURL("CL-NewProductsTour.txt",MyListCount)

 

  If MyListIndex > 1 Then

    Response.Write "<A HREF='" & MyFirstPage& "'>Home</A><BR>"

    Response.Write "Back: <A HREF='" &MyPagePrevious & "'>" &_

                    MyDescriptPrevious &"</A> <BR>"

  End If


  If MyListIndex < MyListCount Then

    Response.Write "Next: <A HREF='" &MyPageNext & "'>" &_

                    MyDescriptNext &"</A> <BR>"

    Response.Write "<A HREF='" &MyLastPage & "'>End</A><BR>"

  End If

%>

 

2.   Open up your browser of choice. At the address line, type inthe URL http://my_server_name/BegASPFiles/CL-Hat.asp.Click on the hyperlinks, to move back and forward through the tour.

Chapter11_image010.gif

How It Works

The differences between this file and our previous versionstart with the addition of two more variables:

 

Dim MyFirstPage

Dim MyLastPage

 

We fill the first variable with a URL returned by the GetNthURL method, where we specify to use the firstpage:

 

MyFirstPage =objNL.GetNthURL("CL-NewProductsTour.txt",1)

 

The second variable is filled with the URL returned when weask for the last page in the index file. Since at design time we don't know howmany pages are in the file, we specify the number sitting in the variable MyListCount.

 

MyLastPage =objNL.GetNthURL("CL-NewProductsTour.txt",MyListCount)

 

Now we can include a Homelink if we are not on the first page already.

 

  If MyListIndex > 1 Then

    Response.Write "<A HREF='" &MyFirstPage & "'>Home</A><BR>"

    Response.Write "Back: <A HREF='" &MyPagePrevious & "'>" &_

                    MyDescriptPrevious &"</A> <BR>"

  End If

 

And we add an End link onlyin the cases where we are not already on the last page.

 

  If MyListIndex < MyListCount Then

    Response.Write "Next: <A HREF='" &MyPageNext & "'>" &_

                    MyDescriptNext &"</A> <BR>"

    Response.Write "<A HREF='" &MyLastPage & "'>End</A><BR>"

  End If

<< 11.3.4- Using the Content Linker and Control Structures to Display Only Appropriate LinksChapter1111.3.6- Using the ASP Content Linker to Generate a Table of Contents >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |