ASP Content Rotator (ASP 3.0)
- Previous Page ASP ContentLinking
- Next Page AJAX Introduction
Example
- Content Rotator component
- This component displays different HTML content strings each time a user accesses or refreshes a page.
ASP Content Rotator component
The ASP Content Rotator component creates a ContentRotator object that displays a different HTML content string each time a user accesses or refreshes a page. A text file named the Content Schedule File contains information about the content strings.
Content strings can contain HTML tags, allowing you to display any content that HTML can present: text, images, colors, or hyperlinks.
Syntax
<% Set cr=Server.CreateObject("MSWC.ContentRotator") %>
Each time a user views the webpage, the following example will display different content. First, create a file named "textads.txt" in a subfolder named "text" in the root directory of the site.
"textads.txt":
%% #1 This is a great day!! %% #2 <h1>Smile</h1> %% #3 <img src="smiley.gif"> %% #4 Here's a <a href="http://www.codew3c.com">link</a>
Note:At the beginning of each content string, there is a #number. This number is an optional parameter used to specify the relative weight of the HTML content string. In this example, the Content Rotator has a one-tenth chance to display the first content string, a one-fifth chance to display the second content string, a one-third chance to display the third string, and the fourth string has a one-fourth chance.
Then, create an ASP file and insert the following code:
<html> <body> <% set cr=server.createobject("MSWC.ContentRotator") response.write(cr.ChooseContent("text/textads.txt")) %> </body> </html>
Methods of the ASP Content Rotator component
Method | Description | Example |
---|---|---|
ChooseContent | Get and display a specific content string |
<% dim cr Set cr=Server.CreateObject("MSWC.ContentRotator") response.write(cr.ChooseContent("text/textads.txt")) %> Output: |
GetAllContent | Retrieve and display all content strings from the text file |
<% dim cr Set cr=Server.CreateObject("MSWC.ContentRotator") response.write(cr.GetAllContent("text/textads.txt")) %> Output: |
- Previous Page ASP ContentLinking
- Next Page AJAX Introduction