ASP 3.0 Advanced Programming (26)

Source: Internet
Author: User
Tags add object count relative reset string access
Programming | Advanced 6.2.6 Content Rotator Components
The Content Rotator component, like a simplified Ad Rotator component, needs to provide a contents dispatch file. The file is only a text file that contains text segments and HTML code snippets, and the Content Rotator component automatically displays one of them on the page. A dispatch table file can include any number of text content entries, and can specify ratios to control how often each entry in a returned page is displayed.
1. Content Dispatch File
The structure of the content progress file is simpler than the Ad Rotator dispatch file, which simply provides a list of the individual text strings to be used, as indicated by a statement line preceded by a two percent sign (%). To set the rate of each entry (which determines how often it appears on the return page), add a number after the double percent semicolon, and then add a comment with a pair of forward slash characters (//). Such as:
% 3//This is the the entry of the schedule text file
For more information, mail us at
<a Href=mailto:feedback@wrox.com>wrox press</a>

% 4//this is a multi-line text string
<UL>
<LI> Language Primers
<LI> Advanced Programming
<LI> Internet Applications
</UL>

%% 2
Visit us on the <a href= "http://www.wrox.com" >world Wide

This example illustrates the three text strings that can be used in a Web page, with ratios of 3, 4, and 2, so entries will appear at 3/9, 4/9, and 2/9 frequencies. Note (as with the Ad Rotator component) the actual occurrence of each string is random, and then the corresponding ratio is corrected, and if the page is transferred nine times, this result may not happen.
2. Members of the Content Rotator component
The Content Rotator component provides only two methods for retrieving contents from a content dispatch file, as shown in table 6-5:
Table 6-5 Content Rotator Component Method and description
Method
Description

GetAllContent (Schdule_file)
Retrieve and display all strings in the Schdule_file file

ChooseContent (Schdule_file)
Retrieves (but does not show) the next appropriate content string from the Schdule_file file

3. Using the Content Rotator component
To obtain text and HTML for a specified segment from a dispatch file, you can use the ChooseContent method of the object to retrieve an entry, according to the rate specified in the content dispatch file. You can use the Response.Write method to insert it into the output stream sent to the guest room.
<% ' in VBScript:
Set objmycontent = Server.CreateObject ("MSWC. ContentRotator ")
Strcontent = Objmycontent.choosecontent ("Contentrotator/content_schedule.txt")
Response.Write Strcontent
%>
This code uses a schedule file in the same directory as the page, and if the code is stored elsewhere, it must indicate the path to the dispatch file, which can be a physical path relative to the root of the Web site or a complete virtual path.
Objmycontent.choosecontent ("\content\mycontent.txt") ' Relative physical path
Objmycontent.choosecontent ("/demo/mycontent.txt") ' Full virtual path '
If you want to display all the content strings in a content dispatch file, you can use the GetAllContent method of the object, as in the case of the Chooseacontent method, to provide a path to the dispatch file. For example, the following code gets all the content in the content dispatch file and displays it in the Web page. Note that this method automatically inserts content into the Web page, so you don't have to use the Response.Write method, and this method automatically adds a horizontal line between each entry.
Objmycontent.getallcontent ("Mycontent.txt")
To study the role of the Content Rotator component, open the provided sample page from the "ASP Installable Components" main menu, which uses the previously described content scheduling file. Call the ChooseContent method, place an entry at the top of the page, and then use the GetAllContent method to display the contents of all the entries in the dispatch file. The Content Rotator Component Sample page is shown in Figure 6-9:

Figure 6-9 Content Rotator Component Sample page

6.2.7 Page Counter Component
The page counter component is used to count the number of times each page is accessed, which periodically stores the statistics in a text file on the server disk-the Access count data file (Hit Count), so that the current data is not lost when there is an outage or error message.
1. Member of Page Counter component
The Page counter component provides a way to increase the number of visits to the file and to read and reset the sum of access counts, as shown in table 6-6:
Method
Description

Hits ([Page_path])
Returns the number of accesses to the Web page specified by Page_path, and returns the number of accesses to the current page if the option Page_path omitted

PageHit ()
Increase the number of visits to the current page

Reset ([Page_path])
Sets the number of accesses to the Web page specified by Page_path to 0, and if the option Page_path omitted, set the current page number of visits to 0

2. Using the page Counter component
The following example uses the JScript language to illustrate the use of the page counter component, first creating an object instance with the Server.CreateObject method, and then invoking the hits method to get the number of accesses to the current page. If the number of visits reaches 5 times, the counter is reset to 0, and a link is placed in the Web page to pass the score to the visitor.
<%//In JScript:
var objpagecount = Server.CreateObject (' MSWC. PageCounter ');

Look for a command sent the FORM section buttons

Increment the counter and display the current hit count
Objpagecount.pagehit ();
Response.Write (' You are visitor number ' + objpagecount.hits () + ' <P> ');

We treat every fifth visitor as a winner
if (objpagecount.hits () = = 5) {
Objpagecount.reset (); Reset the Counter
Response.Write (' you\ ' re a Lucky winner!<br> ');
Response.Write (' <a href= ' winner.asp ' >go to our winners page</a><br> ');
}
%>
Note in the second Response.Write statement, the use of the backslash (\) is to prevent the JScript engine from using the quotation marks as the end of the string.
This book provides a use of page Co



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.