Display advertisements using AdRotator control

Display advertisements using the AdRotator control. Use XML file to store advertisements.

Answer:

AdRotator Control:
The ASP AdRotator component creates an AdRotator object that displays a new image each time a user refreshes or enters the page.

AdRotator control adds the image that, when clicked, navigates to the new web location each time. It defines the following attributes of each node except for ImageUrl, these attributes are optional.

i. ImageUrl
ii. NavigateUrl
iii. AlternateText
iv. Keyword
v. Impression

In the below application, we use AdRotator control to display different images each time and XML file to store the advertisement. The images are automatically changed when user refreshes  the page.  

Advertisement.xml

<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>

   <Ad>
      <ImageUrl>images/new/computer.jpg</ImageUrl>
      <NavigateUrl>http://www.careerride.com</NavigateUrl>
      <AlternateText>Desktops</AlternateText>
      <Keyword>Computers</Keyword>
      <Impressions>80</Impressions>
   </Ad>

   <Ad>
      <ImageUrl>images/new/laptop.jpg</ImageUrl>
      <NavigateUrl>http://www.tutorialride.com</NavigateUrl>
      <AlternateText>Laptop</AlternateText>
      <Keyword>Computers</Keyword>
      <Impressions>80</Impressions>
   </Ad>

   <Ad>
      <ImageUrl>images/new/books.jpg</ImageUrl>
      <NavigateUrl>http://www.tutorialride.com</NavigateUrl>
      <AlternateText>Books</AlternateText>
      <Keyword>Books</Keyword>
      <Impressions>80</Impressions>
   </Ad>

</Advertisements>


Ad-rotator.aspx

<!DOCTYPE html>
   <script language="VB" runat="server">
   </script>
   <html xmlns="http://www.w3.org/1999/xhtml">
   <head runat="server">
       <title>Advertisement Page</title>
   </head>
   <body>
        <h3>AdRotator Example</h3>
        <form id="form1" runat="server">
                <asp:AdRotator id="ar1" AdvertisementFile="Advertisement.xml" BorderWidth="1" runat=server />
        </form>
   </body>
</html>


Output:

1. Run the above program. When we click on the image, it goes to another web page.

adrotator control example

2. Refresh the page, the output will be changed

adrotator control example