Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD

Adrotator control in asp.net - Part 31

Suggested Videos
Part 28 - Bulleted list in asp.net
Part 29 - List controls in asp.net
Part 30 - Fileupload control in asp.net

In this video we will learn about using the asp.net adrotator control. Adrotator control is used to display random ads. The ads information can be stored in an xml file or in a database table. In this video we will discuss about using an XML file.

XML file attributes
ImageUrl - The URL of the image to display
NavigateUrl - The URL to navigate to, when the ad is clicked
AlternateText - The text to use if the image is missing
Keyword - Used by the adrotator control to filter ads
Impressions - A numeric value (a weighting number) that indicates the likelihood of how often the ad is displayed. 



Create an asp.net web application project, and add an XML file. Name the XML file as AdsData.xml. Copy and paste the following in the XML file.
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
  <Ad>
    <ImageUrl>~/Images/Google.png</ImageUrl>
    <NavigateUrl>http://google.com</NavigateUrl>
    <AlternateText>Please visit http://www.Google.com</AlternateText>
    <Impressions>10</Impressions>
  </Ad>
  <Ad>
    <ImageUrl>~/Images/Pragim.png</ImageUrl>
    <NavigateUrl>http://pragimtech.com</NavigateUrl>
    <AlternateText>Please visit http://www.pragimtech.com</AlternateText>
    <Impressions>20</Impressions>
  </Ad>
  <Ad>
    <ImageUrl>~/Images/Youtube.png</ImageUrl>
    <NavigateUrl>http://Youtube.com</NavigateUrl>
    <AlternateText>Please visit http://www.Youtube.com</AlternateText>
    <Impressions>40</Impressions>
  </Ad>
</Advertisements>



Create an Images folder in the project, and add the following images.





Drag and Drop the AdRotator control on the webform. Set AdvertisementFile="~/AdsData.xml".
<asp:AdRotator AdvertisementFile="~/AdsData.xml" ID="AdRotator1" runat="server" />

To open the target web page in a separate browser window, set Target="_blank"

Use KeyWord attribute to filter ads.

The KeywordFilter and AdvertisementFile properties can be changed at runtime also. Changing the KeywordFilter at runtime could be very useful. For example, when the AdRotator control is on a master page, and if you want to change the KeywordFilter on each content page based on the keyword density, so that, only the ads targeting the page content can be displayed. More on this, when we discuss about master pages in a later video session.

1 comment:

  1. Hi

    i am giving same code for the my web application but it 's not working
    i am giving the address of xml file as-


    error is:-
    Server Error in '/' Application.

    The AdRotator AdRotator1 could not find the AdvertisementFile or the file is invalid.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The AdRotator AdRotator1 could not find the AdvertisementFile or the file is invalid.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Please Help me

    ReplyDelete

If you like this website, please share with your friends on facebook and Google+ and recommend us on google using the g+1 button on the top right hand corner.