In my ASP tutorial you will learn about ASP, and how to execute scripts on your server.

ASP Tutorial: ASP AdRotator Component

ASP AdRotator Component



Examples


Simple
AdRotator Example


This example shows how to use the AdRotator component to display a different
advertisement image, each time a user visits or refreshes the page.


AdRotator
- The Images are Hyperlinks


This example shows how to use the AdRotator component to display a different
advertisement image, each time a user visits or refreshes the page. In addition,
the images are hyperlinks.




ASP AdRotator Component


The ASP AdRotator component creates an AdRotator object that
displays a different image each time a user enters or refreshes a page. A text
file includes information about the images.


Syntax








<%

set adrotator=server.createobject("MSWC.AdRotator")

adrotator.GetAdvertisement("textfile.txt")

%>






Example


Assume we have a file called "banners.asp". It looks
like this:








<html>

<body>

<%

set adrotator=Server.CreateObject("MSWC.AdRotator")

response.write(adrotator.GetAdvertisement("ads.txt"))

%>

</body>

</html>

The file "ads.txt" looks like this:








*

w3schools.gif

http://www.w3schools.com/

Visit W3Schools

80

microsoft.gif

http://www.microsoft.com/

Visit Microsoft

20

The lines below the asterisk in the file "ads.txt"
specifies the images to be displayed, the hyperlink addresses, the alternate
text (for the images), and the display rates in percent of the hits. We see that
the W3Schools image will be displayed for 80 % of the hits and the Microsoft
image will be displayed for 20 % of the hits in the text file above.


Note: To get the links to work when a user clicks on
them, we will have to modify the file "ads.txt" a bit:








REDIRECT banners.asp

*

w3schools.gif

http://www.w3schools.com/

Visit W3Schools

80

microsoft.gif

http://www.microsoft.com/

Visit Microsoft

20

The redirection page (banners.asp) will now receive a
querystring with a variable named URL containing the URL to redirect to.


Note: To specify the height, width, and border of the
image, you can insert the following lines under REDIRECT:








REDIRECT banners.asp

WIDTH 468

HEIGHT 60

BORDER 0

*

w3schools.gif

...

...

The last thing to do is to add some lines of code to the
"banners.asp" file:








<%

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!!




Properties

























Property Description Example
Border Specifies the size of the borders around the
advertisement
<%

set adrot=Server.CreateObject("MSWC.AdRotator")

adrot.Border="2"

Response.Write(adrot.GetAdvertisement("ads.txt"))

%>
Clickable Specifies whether the advertisement is a hyperlink <%

set adrot=Server.CreateObject("MSWC.AdRotator")

adrot.Clickable=false

Response.Write(adrot.GetAdvertisement("ads.txt"))

%>
TargetFrame 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















Method Description Example
GetAdvertisement Returns HTML that displays the advertisement in the
page
<%

set adrot=Server.CreateObject("MSWC.AdRotator")

Response.Write(adrot.GetAdvertisement("ads.txt"))

%>