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! |
David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
|
|
|
|
Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications. FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
|
|
|
|
XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services. FREE! Go There Now!
|
|
|
|
The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
|
|
|
|
In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
|
|
|
|
Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |