Using the ASP.NET AdRotator Control

Here’s where it all starts:

<asp:adRotator AdvertisementFile=”/myads.xml” Runat=”server”/>

Let’s say you want the ads on your site to be at the top or bottom of the page. You merely place the adRotator control wherever you want it on your page. This is one of the built in ASP.Net server controls. As you can see, the property ‘AdvertisementFile’ must point to an xml file. Here, it is named ‘myads.xml’, but you can name it anything you want – but it needs to be in xml format. Therefore, you might want to brush up on the basics of xml if you don’t know what an xml file is. If you know a little about the basics of databases, the format should at least look a little familiar. Just have the path to the xml file an exact one so that the server control can find it, in reference to the page it’s on.If you wanted the URLs loaded in a new blank page, you could add the ‘target’ property inside the adRotator control (target=’blank’).

Here’s the basic format of what’s needed in the xml file:

<Advertisements>
  <Ad>
      <ImageUrl>/Path/Banner.gif</ImageUrl>
      <NavigateUrl>http://aspnet101.com</NavigateUrl>
      <AlternateText>
         The best ASP.Net web site in the world!
       </AlternateText>
      <Impressions>3</Impressions>
   </Ad>
</Advertisements>

Here you see that the base tag (Root element) is ‘Advertisements’. All tags which define your particular advertisement/banner will be between the ‘Advertisements’ tags (child elements to the root element). For those of you unfamiliar with xml, think of a database. ‘Advertisements’ is a little like the database container itself. (This illustration is not an exact one, by any means – just a general concept type of illustration.) Then, each particular ad needs to go inside it’s own open/close ‘Ad’ tags. Think, then, of a database table – the ‘Ad’ tags would be the database table. Inside each set of ‘Ad’ tags, you have properties which apply to that particular ‘Ad’, which are also child elements of the Ad child element where it resides. Carrying the database illustration to its end, these properties would then be the fields of the database table. For those of you who are familiar with xml – remember, in this illustration, I’m just trying to break it down to a simple means for anyone to understand.

    The properties in the Ad section are :

  • ImageURL – this is the full path to the banner ad itself
  • NavigateURL. – This is the URL to which the user will go when the banner is clicked
  • AlternateText – This is the same as the Alt Text for any image in HTML.
  • Impressions – here’s how we determine how often the ads run in regards to one another (relative ‘weighting’). The higher the number, the more often the ad will run.

One very nice feature is the ‘Keyword’ feature. You can assign a ‘KeyWord’ child element for each ad, which sort of assigns a category for that ad. Then, in the server control, itself, you can use the KeywordFilter property in the server control. Let’s say you want to only show ads on one page that have to do with Products which are available. You would then add KeywordFilter=”Products”to the server control, and it would only show ads on that page which had the keyword ‘Products’ assigned to the Keyword element in the Ad element.

As I said at the start – it’s not as difficult as it sounds. All you need to do to start is to create an xml file to house the ads, and point to that file in the Advertisements File property of the adRotator server control. That’s all there is to it. Now – just DO IT!

Related Posts:

  • No Related Posts
Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!