Tutorials to .com

Tutorials to .com » Asp » Base » Advanced Programming ASP 3.0 (24)

Advanced Programming ASP 3.0 (24)

Print View , by: iSee ,Total views: 23 ,Word Count: 2904 ,Date: Sat, 25 Apr 2009 Time: 10:18 PM

(1) create a content page
We have the use of Content Linking Component This chapter provides an example for creating a menu page. Chapter06 folder of the page Default.htm in the above code to create the menu, as shown in Figure 6-2:

Figure 6-2 use the Content Linking component to create the menu page
Can see a list of the contents of the document links displayed in the link below, we use the FileSystemObject object to complete this work.
<%
'create an instance of a FileSystemObject object
Set objFSO = Server.CreateObject ( "Scripting.FileSystemObject")

'open the 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
%>
Contlink.txt If you edit a document, call again the next time this page will see the menu entries have changed. To document the last three entries, three entries redirect.asp use of the technology described above, the absolute (not relative) to insert the URL to the list.
(2) to visit these pages
Create a Content Linking component instance and use it as a method, the URL will be the current page content and links to the specified list of documents that match the entries. Not only can the content of the component to create a list (as just seen), but when opened in a browser on one page, you can use the component on the list of all pages for navigation.
This means that the hyperlink can be used or button from the page to another one. For example, pages can be added to the Next and Back button, by using the method GetNextURL and GetPreviousURL list to know which is the previous page, which is the next page. On the other hand, can skip to the list of methods GetNthURL any page GetListIndex methods used to know the current page location in the list.
The following is a section of the page to the Next and Back buttons to add the code, we have to do this procedure only on the content of links listed in the document for each page, or SSI will be the # include directive in which it is inserted.
<! - Need a form to force Navigator to display the buttons ->
<FORM ACTION="">
<%
'we'll insert this into each 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 current page in the list
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 the 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 a Content Linking component, and then the list of file names into a variable in order to create a page in the back of the client in the jscript code can use this list of documents. In addition this would also facilitate the maintenance of the page, because if you want to use a different file name just in one place to change it.
Let us now look at the list in the link position. GetListIndex provide the current page index number, from the list to start the first page. If the index of the current page number to 1, and then back, so we create the page Back button. If the current page index number in the list of more than a few to create Next button. Page always includes a Home button at any time so visitors can easily return to the page content.
If included in the main menu to open the page in one, it will see that we can use this technology to create each page in a series of navigation buttons, the Create button code contlinkbuttons.inc in the document, the # include directive can be used to it inserted into each page. Figure 6-3 shows the interface with a button.

Figure 6-3 with the button interface
In Figure 6-3 there are three buttons, the use of methods GetPreviousDescription on the links page and Add Back to the text of the TITLE attribute of the button, as the pop-up prompts.
<INPUT TYPE = BUTTON VALUE = "<Back"
ONCLICK = "location.href = '<% = objNextLink.GetPreviousURL (strListFile) %>';"
TITLE = "Go to '<% = objNextLink.GetPreviousDescription (strListFile) %>'">
Next button GetNextDescription method used to complete similar work.
(3) javascript Jump
These navigation buttons using JavaScript (not VBScript) loading a new page, it will be able to and compatible with most modern browsers. Back button for example, contains the following attributes:
ONLICK = "location.here = '<% = objNextLink.GetPreviousURL (strListFile)%>';"
When the HTML version of the page created by the ASP, in <% ...%> tags to replace the expression with its value, so sent to the browser page looks as follows:
ONCLICK = "location.herf = 'permissionchecker.asp';"
Why did you choose to use the contents of variables to express in the name of the list of links? The reason is that in a single statement, including a three-tier nested reference is very troublesome.
Attention to your browser's default language is JavaScript (or IE's JScript), rather than VBScript, through the use of JavaScript, can be avoided in the OnClick code LANGUAGE parameters must be provided, at the same time to provide non-IE browser compatibility.

6.2.3 Ad Rotator component
Ad Rotator component to allow the browser in the application of asp pages display different images every time, the technique often used in display ads on the site. Each time you open or when re-loading the page, ASP used "rotating schedule file" (rotator schedule file) of the information to choose an image, and insert the page. Ad Rotator component, however do the work more complicated, it can be set to hyperlink the image rather than a static image, and users can record the number of clicks for each ad.
Described in this chapter of the components, Ad Rotator component may be the most difficult to use because it involves several different files. In the view of each file, as shown in Figure 6-4 Overview of the work process may help to understand the combinations between them.

Figure 6-4 Ad Rotator component of the work process overview
1. Rotation schedule file
Ad Rotator component depends on the document to specify the display ads or images. This document includes the name of each image file, display size and display the relative percentage of the time. The document is divided into two parts, one by one containing only an asterisk (*) separated from the line.
File format is as follows:
REDIRECT URL
WIDTH width
HEIGHT height
BORDER border
*
adURL
adHomeURL
text
impressions
Of which:
URL re-directed the implementation of the ASP file, or program and the name of the virtual path.
Defines the width and height of the ad page size (in pixels), the default value of 440 × 60.
Border advertising provisions of the width of the border (in pixels), the default value of 1, no borders to 0.
The first part is optional, set in the document applies to all advertising of the default values. This set of parameters for all images to provide a method you can use the border width of the Ad Rotator component to set the border attribute. If the neglect of one or more of these optional parameters, and object properties not explicitly set, then use its own parameters and default values. If you ignore all of these parameters need to include "*" as the first line of the document.
The second part, that is, "*" after the part, we must exist in the document, which provides details of the various banner ads. For each ad, the following four parameters to re-use. These parameters are:
AdURL, an advertisement image file of a virtual path and file name.
AdHomeURL, advertising Jump to the URL, a hyphen (-) indicates that the ad does not link.
Text, your browser does not support the graphical display of the text file.
Impressions, is an integer, specified in this ad be shown in the ratio of the relative time or time, for example, a file contains three ads, the impressions and their values were set to 4,6 and 10, then return to the page shows that there are 20% may be the first banner ads, 30% of a second banner ads, 50% of the third banner ads. This article does not specify ad displayed in a browser the actual time. Attention to each of the actual ads are random, and modified to meet the needs of the ratio.
A reorientation of the following documents to see examples:
REDIRECT AdRotFiles / ad_redirect.asp
WIDTH 400
HEIGHT 50
*
Adrotfiles / wrox.gif
http://www.wrox.com/
Better Books from Wrox press
3
AdRotFiles / lunar.gif
http://www.going-to-the-moon.com/store.asp
Acme Lunar Boost Supplies
1
2. Members of the Ad Rotator component
Ad Rotator component contains a method and three properties, methods, such as shown in Table 6-2:
Table 6-2 Ad Rotator component and that
Methods
Description

GetAdvertisement (schedule_file)
The use of specified information in schedule_file to create and return a string, the string containing the image under a suitable insert the required HTML page

Attributes such as shown in Table 6-3:
Properties
Description

Border
Integer type, is the advertising of the border width (in pixels), if set, the first part of the document set using the value of

Clickable
Boolean to provide advertisements whether the image files appear as a hyperlink, the default value of True

TargetFram
String type, the target frame (frame) name. If the user clicks on an image file, then the box used to display the page advertisers. If ignored, the page loaded to the current goal of the browser frame or window to replace the column containing the image of the page ad, this attribute can be set to a standard HTML frames logo: _top, _new, _child, _self, _parent and _blank

3. Use Ad Rotator component
The following code illustrates the use of the Ad Rotator component. After creating a component instance, set attributes and call methods GetAdvertisement, scheduling document specified the relative physical path. By the component to return to the HTML code by using the Response.Write method into the page.
<% 'VBScript example
QUOT = Chr (34)
Set objAdRot = Server.CreateObject ( "MSWC.AdRotator")
objAdRot.Border = 0 'no border
objAdRot.Clickable = TRUE 'is a hyperlink
objAdRot.TargetFrame = "fraAdFrame" 'load into new window named fraAdFrame
strHTML = objAdRot.GetAdvertisement ( "AdRotFiles \ ad_schedule.txt")
Response.Write (strHTML) 'put the HTML into the page
%>
GetAdvertisement method parameters are compared with the current directory or the root directory of the Web site schedule file physical path and file name. In the above code, the file named AdRotFiles, located contains ASP pages are running under the current directory a subdirectory. If the file into the root directory of Web sites under the subdirectory AdRotFiles should be used "\ AdRotFiles \ MyAdFile.txt".
GetAdvertisement method call to return to insert a page used to create the HTML code advertising column, for example the rotation schedule file in the first ad, you can get the following code:
<A HREF = "/ AdRotFiles / AdRedirect.asp?
url = http://www.wrox.com/&image=/AdRotFiles/AdPics/wrox.gif ">
<IMG SRC = "/ AdRotFiles / AdPics / wrox.gif"
ALT = "Better Books from Wrox Press" WIDTH = 440 HEIGHT = 60 BORDER = 0> </ A>
Can be seen in conventional <A> tag image files are placed, HREF attribute is set to redirect the name of the file AdRedirect.asp, at the same time advertisers and home page URL of the image used is added to the query string, so when the user clicks advertising column, the paper will be redirected onto the server and run.
4. Redirection document
Redirect ASP file can be a page or an ISAPI DLL is a CGI application, no matter what kind, it must be able to receive and identify the advertisers home page URL and image name parameters. It checks these values and decide what to do next. For example, users will usually be re-directed to the advertising column and the URL, which use the following vbscript code is easy to achieve.
Response.Redirect Request.QueryString ( "url")
However, the reorientation of documents provided to us is not just these. For example, we can click on each ad to statistics the number of users, according to the cost of clicks received by advertising, it will seem particularly useful. This chapter can also be used behind the Counters component introduced to accomplish this task.
...
'get the URL of the advertiser's target page
strAdvertiserURL = Request.QueryString ( "url")
If Instr (strAdvertiserURL, "wrox.com") Then
objCounters.Increment ( "wrox")
Response.Clear
Response.Redirect strAdvertiserURL
End If

If Instr (strAdvertiserURL, "going-to-the-moon") Then
objCounters.Increment ( "lunar")
Response.Clear
Response.Write "Sorry, this isn't a real site ..."
End If
...
.. 'Same for other advertisers
...
Query string contains the image file name in the script should take this into account, if the schedule file, the same advertisers are three different images, each image on a separate track visits.
...
If Instr (strAdvertiserURL, "wrox.com") Then
'this is an advert for the Wrox Press site
Select Case Request.QueryString ( "image")
Case "books.gif"
objCounters.Increment ( "wrox_books")
Case "website.gif"
objCounters.Increment ( "wrox_site")
Case Else
objCounters.Increment ( "wrox_other")
End Select
Response.Clear
Response.Redirect strAdvertiserURL
End If
...
5. Ad Rotator Example of a page
This chapter provides an example of a document includes a demo program Ad Rotator component, it can be seen from the front of the ASP Installable Components to open the main menu. The top of the page shows the name of a schedule file ad_schedule.txt the definition of the rotation of the ads (which can be an example in this chapter Ad RotFiles directory to find a subdirectory ad_shedule.txt), as shown in Figure 6-5:

Figure 6-5 Ad Rotating sample page
The use of the code has been discussed here in the schedule file in an increase of only some entries in order to more clearly show the ad at the time of loading the page changes. If you click on an advertisement will run ad_redirect.asp the redirect called in the document code, and the corresponding page advertisers in the new window opens. Complete the work in front of the code and see the same.
Redirect file in, you can use Counter (created by the Counters component) storage for each instance of ad clicks.
...
If Instr (strAdvertiserURL, "wrox.com") Then
objCounters.Increment ( "wrox")
Response.Clear
Response.Redirect strAdvertiserURL
End If
... The rest of this page Counters components demonstrated the role of the components described below.


Asp Base Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.