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>
<form action="">
<input type="button" onclick="location.href='<% = objNextLink3.GetNthURL(strListFile3, 1) %>';"
Title="First Page" value=" |< ">
<input type="button" onclick="location.href='<% = objNextLink3.GetNthURL(strListFile3, intPrevPage3) %>';" Title="Previous Page" value=" < ">
<input type="button" onclick="location.href='tocexample.asp';" title="contents page" value="Contents">
<input type="button" onclick="location.href='<% = objNextLink3.GetNthURL(strListFile3, intNextPage3) %>';" Title="Next Page" value=" > ">
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles
More By aspfree
developerWorks - FREE Tools! |
The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
|
|
|
|
Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager. FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
|
|
|
|
This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”. FREE! Go There Now!
|
|
|
|
Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data. FREE! Go There Now!
|
|
|
|
Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly. FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |