ASP.NET, Coding

ASP Content Rotator

The Content Rotator Component creates a ContentRotator object that atomatically rotates different HTML content strings on a web page. Each time a user requests the Web page, the object displays a new HTML content string based upon information that you specify in a Content Schedule file. A text file called the Content Schedule file, includes the information about the content strings.

The content strings can contain any HTML tags, so any type of content that HTML can represent: text, images, or hyperlinks can be displayed on the page using this component. For example, this component can be used to rotate through a list of daily quotations or hyperlinks, or to change text and background colors each time the Web page is opened. The ContentRotator object uses a random generator to select which of the weighted content strings is displayed, a string may be repeated. This is most likely to occur if there are few entries in the Content Schedule file, or if one entry is weighted much higher than the others.

Syntax for creating a ContentRotator:

 <%
 Set cr=Server.CreateObject( "MSWC.ContentRotator" )
 %>

The ASP Content Rotator Component’s methods are described below:

Method     Description ChooseContent Gets and displays a content string GetAllContent  Retrieves and displays all of the content strings in the text file

The following simple code snippet explains the use of this very useful component. Say you have a text file named textads.txt in a folder named text inside your webfolder.

"textads.txt":

%% #1
This is a great day!!

%% #2 

Smile

%% #3 %% #4 Here's a link.

Notice the #number at the beginning of each content string. This number is an optional parameter that indicates the relative weight of the HTML content string. In this example, the Content Rotator will display the first content string one-tenth of the time, the second string two-tenths of the time, the third string three-tenths of the time, and the fourth string four-tenths of the time.

Then, create an ASP file, and insert the following code:




 <%
 set cr=server.createobject("MSWC.ContentRotator")
 response.write(cr.ChooseContent("text/textads.txt"))
 %>



You Might Also Like