Using a #include file, the Content Linking component, and IIS 4.0 to create a quick and easy Navigation system for your web.
This demo uses server side #include text file and the Content Linking component. This component is included in the Option pak 4.0 when its installed. This demo will show how to use two text files that resides in your web, one holds the code for the navagation buttons that will be displayed & the necessary ASP code to call the Nextlink method. The 2nd one has a list the pages that you want to be navigated. By the end of this demo I hope you understanding how to use this to create your own quick and easy navigation system using the Content Linking component.
I try to make my demo's original and useful, this idea was discovered when I was reading Wrox Professional ASP Techniques for Webmasters. A plug for Wrox, this book does a good job for me being not so much a newbie anymore but needing how to do more advanced stuff. I thought this was such a cool idea I have to share this on my site. Its an easy concept to grasp-(Or at least I thought so!) that almost anyone could use this. And for those who know me I hate to write lots of code and make things hard. Without further a do the list of things I created for this demo.
#1 A text file created using notepad, it contains the pages you want to be navigated-called contlink.txt. This file contains all the pages listed in order you want them to be displayed & a description. The beauty of this is its very efficient, ie: you want to add file pages and change the order of your site. All you have to change is the text file and the read is automatically changes the rest of the pages already that are created. This is also used by the Table of Contents page to display all possible pages in the web if you want a start page. In this demo its tocexample.asp
Example: Contlink.txt Page Name: Description of page people will see in the hyperlink
page1.asp
This is the 1st page of my demo
page2.asp
This is the 2nd page of my demo
page3.asp
This is the 3rd page of my demo
#2 A text file created using notepad, it contains the code for the buttons that will be used to navigate-called buttons.inc This file contains all the code needed to process so the navigation button's appear correctly on your site.
#3 Finally all the pages that hold the data you want to display these also can be ASP pages or static html.
Note: On these pages you have to put one line of code to call the #include file. This demo isn't meant make you an expert in #include files but using them is very efficient. Using Server-Side #include files are processed the same time the ASP page is generated. Include files can contain preformatted HTML, asp code or anything else that would normally reside on HTML/ASP pages. This is a handy way of maintaining code in one place and having it used on several pages within your website. For more information on #Include files visit www.activeserverpages.com they have a nice page explaining them.
The code that has to be on the page without server-side code tags <% %> around it.
<!-- #include file="buttons.inc"-->
Code for the Table of Contents page
<html> <head> <title>Table of Contents page for Contentlinking demo</title> </head>
<body> <h3>Contents List:</h3> <ul> 'Using the Server.Createobject this is theobject that is created to hold and read the text file that contains 'all the files you want to be displayed in your navigation bars <% set Nextlink = Server.Createobject("MSWC.Nextlink") intCount = Nextlink.GetListCount("contlink.txt") %> 'Write out the values after the file has been read <% For intLoop = 1 to intCount %> <li> 'Uses the GetNthUrl method of the Nextlink object to write out link. Remember in the contlink.txt file you put two 'things, the 'link to the file & the description. The URL gets read into the GetNthRUrl method. The description 'is what the user sees and 'is read into the GetNthDescription method. <a href="<% = Nextlink.GetNthurl("Contlink.txt", intLoop) %>"> <% = NextLink.GetNthDescription("Contlink.txt", intLoop) %> </a> </li> <% Next %> </ul> </body> </html>
Code for the Contlink.txt file
Link of page Description that the user will see page1.asp Page One of contentlinking demo page2.asp Page two of contentlinking demo page3.asp Page three of contentlinking demo
Code for the buttons.inc file
<b>Method # 1 using buttons</b><br> <form action="">
<% set objNextLink = server.createobject("mswc.nextlink") strListFile = "contLink.txt" intThisPage = objNextLink.GetListIndex(strListFile) If (intThisPage) > 1 Then %> <input type="button" onclick="location.href='<% = objNextLink.GetPreviousURL(strListFile) %>';" title="Previous Page" value="Previous"> <% End If %> <input type="button" onclick="location.href='tocexample.asp';" title="Contents Page" value="Contents"> <% If (intThisPage) < objNextLink.GetListCount(strListFile) Then %> <input type="button" onclick="location.href='<% = objNextLink.GetNextURL(strListFile) %>';" title="Next Page" value="Next page"> <% End If %> </form><br><br>
<b>Method # 2 using numbers on the page</b><br> <% set obj2NextLink = server.createobject("mswc.nextlink") strListFile2 = "contlink.txt" intThisPage2 = obj2NextLink.GetListIndex(strListFile) intLastPage2 = obj2NextLink.GetListCount(strListFile)
For intLoop2 = 1 to IntLastPage2 If intThispage2 <> intloop2 Then response.write "<a href=" & chr(34) _ & obj2nextlink.getNthurl(strListFile2, intLoop2) & chr(34) & ">" End If response.write intLoop2 If intThisPage2 <> intLoop2 Then response.write "</a>" End if response.write " " Next %> <a href="tocexample.asp">Content</a> <br><br> <% strListFile3 = "contlink.txt" set objNextLink3 = server.createobject("mswc.nextlink") intListCount3 = objnextLink3.GetListCount(strlistfile) intCurrentPage3 = objNextLink3.GetListIndex(strlistfile) If intCurrentPage3 > 1 Then intPrevPage3 = intCurrentPage3 - 1 Else intPrevPage3 = intListCount3 End If If intCurrentPage3 < intListCount3 Then intNextPage3 = intCurrentpage3 + 1 Else intNextPage3 = 1 End If %> <br> <b>Method # 3 using navigation buttons similiar to the ones used on Microsoft Access forms</b><br>