FREE tutorial,solution,RSS Feeds on Operating Systems, Programming, Web Development, Applications, Databases, Networking, Hardware, Security, SEO Free Expertsforge Membership
Join us as Moderator
Submit Article to Expertsforge.com Submit Article My Expertsforge
 
RSS Feeds, Help Help RSS Feeds
bannertop
 

ASP Tutorial: Displaying random image or banner using ASP AdRotator component

jawahar
5/20/2005 4:56:48 PM, Views: 2274
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:

*
expertsforge.gif
http://www.expertsforge.com/
Visit expertsforge
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 expertsforge 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
*
expertsforge.gif
http://www.expertsforge.com/
Visit expertsforge
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
*
expertsforge.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!!
Next Steps:
Add this Tutorial to:
Blink Blink del.icio.ous Del.icio.us Digg Digg
Fark Fark Furl Furl Google Google
Reddit Reddit Simpy Simpy Spurl Spurl
Technorati Technorati Windows Live Win Live Yahoo Yahoo
Rate Me!
Not Yet Rated!
Rate:
Send Private MessageSend Message
Signup / Login To View the Solution or Provide Comments
Post Comment/Solution
Comment:*
        (Link Rules) 
  Use : [bold] for <b>; [/bold] for </b>; [italic] for <i>; [/italic] for </i>; [code] & [/code] for code
 
Categories
Options
ASP RSS Feed
Most Popular Tutorial
Most Popular Solution
Top Rated
Top Contributors
Yearly
Overall
 
1. jawahar (200)
bnrtop