ASP AdRotator Component

Example

Simple AdRotator Example
This example demonstrates: How to use the AdRotator component to display a different advertisement image every time a user visits the website or refreshes the page.
AdRotator - Image Link
This example demonstrates: How to use the AdRotator component to display a different advertisement image every time a user visits the website or refreshes the page. In addition, the image itself is a link.

ASP AdRotator Component

Every time a user enters the website or refreshes the page, the ASP AdRotator component creates an AdRotator object to display a different image.

Syntax:

<%
set adrotator=server.createobject("MSWC.AdRotator")
adrotator.GetAdvertisement("textfile.txt")
%>

Example

Suppose we have a file named "banners.asp". It is similar to this:

<html>
<body>
<%
set adrotator=Server.CreateObject("MSWC.AdRotator")
response.write(adrotator.GetAdvertisement("ads.txt"))
%>
</body>
</html>

The file "ads.txt" looks like this:

*
codew3c.gif
http://www.codew3c.com/
Visit CodeW3C.com
80
microsoft.gif
http://www.microsoft.com/
Visit Microsoft
20  

The code below the asterisk in the "ads.txt" file defines how to display these images, link addresses, alternative text for images, and the probability of display in every hundred clicks. We can see that the display probability of the CodeW3C.com image is 80%, while the display probability of the Microsoft image is 20%.

Note:To make these links work properly when clicked by the user, we need to make a small modification to the file "ads.txt":

REDIRECT banners.asp
*
codew3c.gif
http://www.codew3c.com/
Visit CodeW3C.com
80
microsoft.gif
http://www.microsoft.com/
Visit Microsoft
20

The redirect page will receive a query string variable named url, which contains the URL for redirection.

Note:If you need to specify the height, width, and border of the image, you can insert the following code below REDIRECT:

REDIRECT banners.asp
WIDTH 468 
HEIGHT 60 
BORDER 0 
*
codew3c.gif
...
...

Finally, you need to add this code to the file "banners.asp":

<%
url=Request.QueryString("url")
If url<>"" then Response.Redirect(url)
%>
<html>
<body>
<%
set adrotator=Server.CreateObject("MSWC.AdRotator")
response.write(adrotator.GetAdvertisement("textfile.txt"))
%>
</body>
</html>

That's all for the content!

Attributes of the AdRotator Component

Border Attribute

Specifies the size of the border around the advertisement.

<%
set adrot=Server.CreateObject("MSWC.AdRotator")
adrot.Border="2"
Response.Write(adrot.GetAdvertisement("ads.txt"))
%>

Clickable Attribute

Specifies whether the advertisement itself is a hyperlink.

<%
set adrot=Server.CreateObject("MSWC.AdRotator")
adrot.Clickable=false
Response.Write(adrot.GetAdvertisement("ads.txt"))
%>

TargetFrame Attribute

The name of the frame to display the advertisement.

<%
set adrot=Server.CreateObject("MSWC.AdRotator")
adrot.TargetFrame="target='_blank'"
Response.Write(adrot.GetAdvertisement("ads.txt"))
%>

Methods of the AdRotator Component

GetAdvertisement Method

Return the HTML that displays the advertisement in the page.

<%
set adrot=Server.CreateObject("MSWC.AdRotator")
Response.Write(adrot.GetAdvertisement("ads.txt"))
%>