Thành phần liên kết nội dung ASP


Các ví dụ khác


Xây dựng mục lục.


Sử dụng Thành phần Liên kết Nội dung để điều hướng giữa các trang trong tệp văn bản.


Thành phần liên kết nội dung ASP

Thành phần Liên kết nội dung ASP được sử dụng để tạo một hệ thống điều hướng nhanh chóng và dễ dàng!

Thành phần Liên kết Nội dung trả về một đối tượng Nextlink được sử dụng để chứa danh sách các trang Web được điều hướng.

Cú pháp

<%
Set nl=Server.CreateObject("MSWC.NextLink")
%>

Ví dụ về liên kết nội dung ASP

Đầu tiên, chúng tôi tạo một tệp văn bản - "links.txt":

asp_intro.asp ASP Intro
asp_syntax.asp ASP Syntax
asp_variables.asp ASP Variables
asp_procedures.asp ASP Procedures

Tệp văn bản ở trên chứa các trang được điều hướng. Các trang phải được liệt kê theo thứ tự mà bạn muốn chúng được hiển thị và nó cũng phải chứa mô tả cho từng tên tệp (sử dụng phím tab để tách tên tệp khỏi mô tả).

Lưu ý: Nếu bạn muốn thêm một trang hoặc thay đổi thứ tự của các trang trong danh sách; bạn chỉ phải sửa đổi tệp văn bản! Điều hướng sẽ tự động được sửa chữa!

Sau đó, chúng tôi tạo một tệp bao gồm, "nlcode.inc". Tệp .inc tạo một đối tượng NextLink để điều hướng giữa các trang được liệt kê trong "links.txt".

"nlcode.inc":

<%
dim nl
Set nl=Server.CreateObject("MSWC.NextLink")
if (nl.GetListIndex("links.txt")>1) then
  Response.Write("<a href='" & nl.GetPreviousURL("links.txt"))
  Response.Write("'>Previous Page</a>")
end if
Response.Write("<a href='" & nl.GetNextURL("links.txt"))
Response.Write("'>Next Page</a>")
%>

Trong mỗi trang .asp được liệt kê trong tệp văn bản "links.txt", hãy đặt một dòng mã: <! - #include file = "nlcode.inc" -> . Dòng này sẽ bao gồm mã trong "nlcode.inc" trên mọi trang được liệt kê trong "links.txt" và điều hướng sẽ hoạt động.



Phương pháp của thành phần liên kết nội dung ASP

Method Description Example
GetListCount Returns the number of items listed in the Content Linking List file <%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetListCount("links.txt")
Response.Write("There are ")
Response.Write(c)
Response.Write(" items in the list")
%>

Output:

There are 4 items in the list

GetListIndex Returns the index number of the current item in the Content Linking List file. The index number of the first item is 1. 0 is returned if the current page is not in the Content Linking List file <%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetListIndex("links.txt")
Response.Write("Item number ")
Response.Write(c)
%>

Output:

Item number 3

GetNextDescription Returns the text description of the next item listed in the Content Linking List file. If the current page is not found in the list file it returns the text description of the last page on the list <%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetNextDescription("links.txt")
Response.Write("Next ")
Response.Write("description is: ")
Response.Write(c)
%>

Next description is: ASP Variables

GetNextURL Returns the URL of the next item listed in the Content Linking List file. If the current page is not found in the list file it returns the URL of the last page on the list <%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetNextURL("links.txt")
Response.Write("Next ")
Response.Write("URL is: ")
Response.Write(c)
%>

Next URL is: asp_variables.asp

GetNthDescription Returns the description of the Nth page listed in the Content Linking List file <%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetNthDescription("links.txt",3)
Response.Write("Third ")
Response.Write("description is: ")
Response.Write(c)
%>

Third description is: ASP Variables

GetNthURL Returns the URL of the Nth page listed in the Content Linking List file <%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetNthURL("links.txt",3)
Response.Write("Third ")
Response.Write("URL is: ")
Response.Write(c)
%>

Third URL is: asp_variables.asp

GetPreviousDescription Returns the text description of the previous item listed in the Content Linking List file. If the current page is not found in the list file it returns the text description of the first page on the list <%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetPreviousDescription("links.txt")
Response.Write("Previous ")
Response.Write("description is: ")
Response.Write(c)
%>

Previous description is: ASP Variables

GetPreviousURL Returns the URL of the previous item listed in the Content Linking List file. If the current page is not found in the list file it returns the URL of the first page on the list <%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetPreviousURL("links.txt")
Response.Write("Previous ")
Response.Write("URL is: ")
Response.Write(c)
%>

Previous URL is: asp_variables.asp