ASP 3.0 Advanced Programming (24)

Source: Internet
Author: User
Tags add object end include insert interface numeric value return
Programming | Advanced (1) Create a content page
We have used the content linking component to create a menu page for the examples provided in this chapter. The page in the Chapter06 folder default.htm use the code above to create the menu, as shown in Figure 6-2:

Figure 6-2 Menu page created using the Content Linking component
You can see that the contents of the Content Link list file are displayed below the link, and we use the FileSystemObject object to do this work.
<%
' Create an instance of a FileSystemObject object
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")

' Open ' text file as a TextStream object
Set Objtstream = objFSO.OpenTextFile (Server.MapPath ("Contlink.txt"), ForReading)
Response.Write Objtstream.readall ' Read the whole file and put into page
Objtstream.close
%>
If you edit the Contlink.txt file, the next time you call the page, you will see that the menu entry has changed. Note the last three entries in the file, which use the redirect.asp technique described earlier to insert an absolute (not a relative) URL into the list.
(2) Browse these pages
When you create a content linking instance of a component and use one of its methods, the URL of the current page matches the entry in the specified Content link list file. Not only can you create a list of content with this component (as you just saw), but when you open one of the pages in a browser, you can use that component to navigate through each page in the list.
This means that you can use hyperlinks or buttons to move from one of these pages to another. For example, you can add the next and Back buttons to a page by using the GetNextURL and GetPreviousURL methods to know which page in the list is the previous and which is the next. On the other hand, you can use the GetNthURL method to jump to any page in the list and use the GetListIndex method to know where the current page is in the list.
Here's a piece of code to add next and Back buttons to the page, and all we have to do is place the program on every page listed in the Content Link file, or insert it in the #include instruction of SSI.
<!--need a form to force Navigator to display the buttons-->
<form action= "" >
<%
' We'll insert this into the page using an SSI #include statement
' Create an instance of the Content linking component
Set Objnextlink = Server.CreateObject ("MSWC. Nextlink ")
' Set the Content Linking list file path and name
Strlistfile = "Contlink.txt"
' Get the ' Index of the '
Intthispage = Objnextlink.getlistindex (strlistfile)
If intthispage > 1 Then ' can go back
%>
<input Type=button value= "< back"
onclick= "location.href= ' <% = Objnextlink.getpreviousurl (strlistfile)%> ';"
Title= "Go to" <% = Objnextlink.getpreviousdescription (strlistfile)%> ' ">

<%
End If
%>
<input Type=button value= "menu" onclick= "location.href= ' default.asp ';"
Title= "Return to" main ' installable Components ' menu ' >
<%
If Intthispage < Objnextlink.getlistcount (strlistfile) Then ' can go forward
%>

<input Type=button value= "Next >"
onclick= "location.href= ' <%= objnextlink.getnexturl (strlistfile)%> ';"
Title= "Go to" <% = Objnextlink.getnextdescription (strlistfile)%> ' ">
<%
End If
%>
</FORM>
The first step is to create the content linking component, and then save the list file name in a variable so that you can use the list file later when you create the client JScript code in the page. This also makes it easier to maintain the page, because if you want to use a different filename, you need to change it in one place.
Now let's take a look at where we are in the list of links. The GetListIndex method provides the index number of the current page, starting at the first page in the list. If the index number of the current page is larger than 1, then you can rewind it, so we create the back button on the page. If the current page has fewer index numbers than the number of items in the list, create a Next button. A home button is always included in the page so that visitors can easily return to the content page at any time.
If you open one of the pages listed in the main menu, you will see a series of navigation buttons created on each page using this technique, and the code to create the button is in file Contlinkbuttons.inc and can be inserted into each page with the #include instruction. Figure 6-3 shows the interface with a button.

Figure 6-3 Interface with a button
In Figure 6-3, there are three buttons, using the GetPreviousDescription method to get the link file from the previous page, and putting this text in the title property of the Back button as a pop-up hint.
<input Type=button value= "< back"
onclick= "location.href= ' <% = Objnextlink.getpreviousurl (strlistfile)%> ';"
Title= "Go to" <% = Objnextlink.getpreviousdescription (strlistfile)%> ' ">
The Next button uses the GetNextDescription method to do similar work.
(3) Use JavaScript to jump
These navigation buttons use JavaScript (rather than VBScript) to load new pages so that they are compatible with most modern browsers. For example, the Back button contains the following properties:
onlick= "location.here= ' <% = Objnextlink.getpreviousurl (strlistfile)%> '"; "
When an HTML version of a page is created by an ASP, the expression in the <%...%> tag is replaced with its numeric value, so the page that is sent to the browser looks like this:
onclick= "location.herf= ' permissionchecker.asp"; "
Why choose to use variables to represent the name of a content link list file? The reason is that it is cumbersome to include a three-layer nested reference in a single statement.
Note that the default language of the browser is JavaScript (or JScript in IE), not VBScript, by using the JA



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.