AdRotator Class
Provides the control capability to display a randomly selected advertisement on a mobile page.
public class System.Web.UI.MobileControls.AdRotator :
System.Web.UI.MobileControls.MobileControl
Remarks
The AdRotator class uses the same configuration file as the Web Forms AdRotator class. The AdRotator mobile control exposes many of the same properties and events as the AdRotator Web Server Control, plus it adds mobile capability for the control. At run time, the AdRotator control creates and uses a Web Forms AdRotator control for its logic, and thus shares the same configuration file. The displayed advertisement changes whenever the page is refreshed.
The AdvertisementFile property specifies the location of an XML file that contains advertisement information. This file must reside within the application domain. If the AdvertisementFile property is empty, the AdRotator control generates a single break tag as a placeholder. This is useful when you do not want to display an advertisement.
Example
This following code example has two parts, an ASP.NET mobile Web Forms page in an .aspx file and an XML file. The .aspx file accesses a file called ads.xml. It uses this file to rotate through various advertisements. If you provide images, they will be displayed; otherwise, the AdRotator control displays the value of the AlternateText for the advertisements. When the user refreshes the mobile Web Forms page, the page displays a random advertisement.
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage"
Language="VB" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script language="VB" runat="server">
Sub AdCreated_Event(sender As Object, e As AdCreatedEventArgs)
Label2.Text = "Clicking the AdRotator control takes you to " + _
e.NavigateURL
End Sub
</script>
<mobile:Form runat="server" id="Form1" >
<mobile:AdRotator id="AdrHeader" runat="server"
AdvertisementFile="ads.xml" Alignment="Left"
OnAdCreated="AdCreated_Event"/>
<mobile:Label id="Label1" runat="server"
Text="Refresh the page to change the advertisement" />
<mobile:Label id="Label2" runat="server" />
</mobile:Form>
[C#]
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage"
Language="c#" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script language="c#" runat="server">
void AdCreated_Event(Object sender, AdCreatedEventArgs e)
{
Label2.Text = "Clicking the AdRotator control takes you to " +
e.NavigateURL;
}
</script>
<mobile:Form runat="server" id="Form1" >
<mobile:AdRotator id="AdrHeader" runat="server"
AdvertisementFile="ads.xml" Alignment="Left"
OnAdCreated="AdCreated_Event"/>
<mobile:Label id="Label1" runat="server"
Text="Refresh the page to change the advertisement" />
<mobile:Label id="Label2" runat="server" />
</mobile:Form>
The following is an example of an advertisement file, Ads.xml.
<?xml version="1.0" ?>
<Advertisements>
<Ad>
<ImageUrl>gif1.gif</ImageUrl>
<NavigateURL>https://msdn.microsoft.com/</NavigateURL>
<AlternateText>MSDN</AlternateText>
</Ad>
<Ad>
<ImageUrl>gif2.gif</ImageUrl>
<NavigateURL>https://www.microsoft.com/</NavigateURL>
<AlternateText>Microsoft</AlternateText>
</Ad>
<Ad>
<ImageUrl>gif3.gif</ImageUrl>
<NavigateURL>https://www.microsoft.com/net/</NavigateURL>
<AlternateText>NET</AlternateText>
</Ad>
</Advertisements>
Requirements
Namespace: System.Web.UI.MobileControls
Assembly: System.Web.Mobile
See Also
AdRotator Control | System.Web.UI.WebControls.AdvertisementFile Property