In ASP.NET, the AdRotator control is used to display advertisements (ads) on a webpage in a rotating manner. It allows you to define multiple ads and their corresponding attributes such as image, URL, alternate text, and more, and then displays these ads in a rotating manner.
Here's a basic example demonstrating how to use the AdRotator control in an ASP.NET Web Forms application:
.aspx
file:Example
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<!-- AdRotator control declaration -->
<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/ads.xml" />
</div>
</form>
</body>
</html>
ads.xml
in this example) within your project. This XML file will contain the information about each ad, such as image URL, navigate URL, alternate text, etc. Here's an example of ads.xml
:Example
<Advertisements>
<Ad>
<ImageUrl>ad1.jpg</ImageUrl>
<NavigateUrl>https://example.com/ad1</NavigateUrl>
<AlternateText>Ad 1</AlternateText>
</Ad>
<Ad>
<ImageUrl>ad2.jpg</ImageUrl>
<NavigateUrl>https://example.com/ad2</NavigateUrl>
<AlternateText>Ad 2</AlternateText>
</Ad>
<!-- Add more ads here -->
</Advertisements>
This is a basic example to get you started with the AdRotator control. You can customize the appearance and behavior of the ads by setting various properties of the AdRotator control and defining additional attributes for each ad in the XML file. Additionally, you can handle events raised by the AdRotator control to perform custom actions when an ad is clicked or displayed.