AdRotator control in asp.net

5.4k Views Asked by At

I am trying to use the AdRotator control with timing to have a slide show of the images. For which I tried something like this XMLFile1 file

 <?xml version="1.0" encoding="utf-8" ?>
    <Advertisements>
      <Ad>
        <ImageUrl>~\Images\1.jpg</ImageUrl>
        <NavigateUrl>http://www.google.com</NavigateUrl>
        <AlternateText>AdRotator Control sample ads</AlternateText>
        <Impressions>20</Impressions>
        <Keyword>Asp.Net</Keyword>
      </Ad>

      <Ad>
        <ImageUrl>~\Images\2.jpg</ImageUrl>
        <NavigateUrl>http://www.gmail.com</NavigateUrl>
        <AlternateText>AdRotator Control sample ads</AlternateText>
        <Impressions>30</Impressions>
        <Keyword>Asp.Net</Keyword>
      </Ad>
    </Advertisements>

WebForm1.aspx

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TrialVersion.WebForm1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:ScriptManager ID="scriptmanager1" runat="server">
        </asp:ScriptManager>
        <asp:Timer ID="Timer1" runat="server" Interval="500"></asp:Timer>
        <asp:UpdatePanel ID="upanel" runat="server" UpdateMode="Conditional" 
        Visible="False">
        <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
       </Triggers>
       <ContentTemplate>
       <asp:AdRotator id="adrotator" runat="server" AdvertisementFile="~/XMLFile1.xml" KeywordFilter="Asp.Net"/>
       </ContentTemplate>
       </asp:UpdatePanel>

        </div>
        </form>
    </body>
    </html>

On Building this app, it gives me a blank Page and none of the image is displayed. Why thats so.

3

There are 3 best solutions below

0
On

It's because you have Visible="False" in the UpdatePanel. Take that out, and the images should show up.

1
On

Can you check removing all the unnecessary code you have at the top (ScriptManager,Timer and update panel). So you will be able to isolate the problem. I think the problem is not with your ad rotator but with your timer and update panel.

0
On

Instead of giving this

<ImageUrl>~\Images\1.jpg</ImageUrl>

You just give like that

<ImageUrl>Images\1.jpg</ImageUrl>

Hope it will work