Ad Rotator is failing to print the ads

Aug 10, 2012 at 1:48 AM

First of all, congrats for the amazing ad solution but unfortunately I'm having some problems to print the ads.

When a navigate to a page that has an ad, most of the time the ad is not printed and the [i guess] default gray rectangle is printed instead. I thought it was because no ads were available or something like this but here is what is catchy: if a navigate forward and then come back to the page, an ad is always printed.

Any thoughts about what might be happening?

Aug 10, 2012 at 8:56 AM

Hi MoiC4, I've registered to reply to this because I'm having the same trouble. There are a couple of threads which might help you out, they certainly point you in the right direction, I'll link them below.

http://wp7adrotator.codeplex.com/discussions/355707/

http://wp7adrotator.codeplex.com/discussions/355792

For myself, I've followed the instructions in those threads, adding the invalidate code into the OnPageLoaded and OnNavigatedFrom methods, it hasn't fixed the problem. I suspect I'm missing out on something which ought to be obvious, being self-taught can sometimes be detrimental. I would appreciate any help from someone more experienced. I'll post the xaml and the xaml.cs of one of my pages below in case anyone can spot an obvious error.

 

<phone:PhoneApplicationPage 
    x:Class="BreakingBad.Characters.Characters"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:adRotator="clr-namespace:AdRotator;assembly=AdRotator"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
    xmlns:my="clr-namespace:BreakingBad"
    xmlns:my1="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="0,80,0,0">
            <TextBlock x:Name="PageTitle" Text="Characters" Margin="0,0,0,0" Style="{StaticResource PhoneTextTitle1Style}" Grid.RowSpan="2" HorizontalAlignment="Center" />
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,20,0,0">
            <Button Content="Walt's Family" Name="Walt_button" Width="440" Height="80" Margin="0,80,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" Click="Walt_button_Click" />
            <Button Content="Jesse's People" Name="Jesse_button" Width="440" Height="80" Margin="0,150,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" Click="Jesse_button_Click" />
            <Button Content="D.E.A." Name="DEA_button" Width="440" Height="80" Margin="0,220,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" Click="DEA_button_Click" />
            <Button Content="Los Pollos" Name="LosPollos_button" Width="440" Height="80" Margin="0,290,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" Click="LosPollos_button_Click" />
            <Button Content="The Cartel" Name="Cartel_button" Width="440" Height="80" Margin="0,360,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" Click="Cartel_button_Click" />
        </Grid>
        <adRotator:AdRotatorControl DefaultSettingsFileUri="/BreakingBad;component/defaultAdSettings.xml" Name="adRotatorControl" SettingsUrl="http://xna-uk.net/adrotator/SLdefaultAdSettingsV2.xml" SlidingAdDirection="None" VerticalAlignment="Top" Visibility="Visible" />
    </Grid>
</phone:PhoneApplicationPage>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using AdRotator;

namespace BreakingBad.Characters
{
    public partial class Characters : PhoneApplicationPage
    {
        public Characters()
        {
            InitializeComponent();
        }

        private void Walt_button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Characters/WaltsFamily.xaml", UriKind.Relative));
        }

        private void Jesse_button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Characters/JessesPeople.xaml", UriKind.Relative));
        }

        private void DEA_button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Characters/DEA.xaml", UriKind.Relative));
        }

        private void LosPollos_button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Characters/LosPollos.xaml", UriKind.Relative));
        }

        private void Cartel_button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Characters/Cartel.xaml", UriKind.Relative));
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (adRotatorControl.IsInitilised)
            {
                adRotatorControl.Invalidate();
            }
            base.OnNavigatedTo(e);
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            adRotatorControl.Dispose();
            base.OnNavigatedFrom(e);
        }

        private void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            if (adRotatorControl.IsInitilised)
            {
                adRotatorControl.Invalidate();
            }
        }
    }
}

Jan 4, 2013 at 7:48 PM

Hello, I am having the exact same issue.
I launch my app and get a gray rectangle for about 1-2 seconds where the ad control should be and after that nothing. No ads are displayed.
Did anyone find why this happens?

Thanks,
Marius B

Jan 5, 2013 at 2:12 AM

i'm experiencing the same problem when i'm trying to implement the ads outside pivot control, but everything seems to be fine when the ads is inside pivot item.  I'm using WP 8.

Coordinator
Jan 10, 2013 at 4:32 PM

Resurgence of an old post.

blinkk2 - you might want to check out adibt's other post where the issue was caused by issues with the config XML here:

http://wp7adrotator.codeplex.com/discussions/428370

 

Note, it's best to use the NuGet packages to install AdRotator now as it does most of the work for you, leaving you only to add the XAML control and calling Invalidate in the Loaded even in the codebehind,

Also note no need any more to test "adRotatorControl.IsInitilised" as we sort that out internally now.