Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Adrotator control in - Part 31

Suggested Videos
Part 28 - Bulleted list in
Part 29 - List controls in
Part 30 - Fileupload control in

In this video we will learn about using the adrotator control. Adrotator control is used to display random ads. The ads information can be stored in an xml file or in a database table. In this video we will discuss about using an XML file.

XML file attributes
ImageUrl - The URL of the image to display
NavigateUrl - The URL to navigate to, when the ad is clicked
AlternateText - The text to use if the image is missing
Keyword - Used by the adrotator control to filter ads
Impressions - A numeric value (a weighting number) that indicates the likelihood of how often the ad is displayed. 

Create an web application project, and add an XML file. Name the XML file as AdsData.xml. Copy and paste the following in the XML file.
<?xml version="1.0" encoding="utf-8" ?>
    <AlternateText>Please visit</AlternateText>
    <AlternateText>Please visit</AlternateText>
    <AlternateText>Please visit</AlternateText>

Create an Images folder in the project, and add the following images.

Drag and Drop the AdRotator control on the webform. Set AdvertisementFile="~/AdsData.xml".
<asp:AdRotator AdvertisementFile="~/AdsData.xml" ID="AdRotator1" runat="server" />

To open the target web page in a separate browser window, set Target="_blank"

Use KeyWord attribute to filter ads.

The KeywordFilter and AdvertisementFile properties can be changed at runtime also. Changing the KeywordFilter at runtime could be very useful. For example, when the AdRotator control is on a master page, and if you want to change the KeywordFilter on each content page based on the keyword density, so that, only the ads targeting the page content can be displayed. More on this, when we discuss about master pages in a later video session.


  1. Hi

    i am giving same code for the my web application but it 's not working
    i am giving the address of xml file as-

    error is:-
    Server Error in '/' Application.

    The AdRotator AdRotator1 could not find the AdvertisementFile or the file is invalid.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The AdRotator AdRotator1 could not find the AdvertisementFile or the file is invalid.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Please Help me

    1. Assalamu Alikom Neyaz Khan.
      I also face the same problem. check spelling of folder and file Name, upper case ,lower case. Even you can't solve the problem Then copy the code from above and rename the file according to the code! Hope this will work!


It would be great if you can help share these free resources