asp.net.ph

AdRotator.AdvertisementFile Property

System.Web.UI.WebControls Namespace   AdRotator Class


Sets or retrieves the path to the XML file that contains advertisement data.

Syntax


Inline <asp:adrotator advertisementfile = strFilePath ... >
Script AdRotator.AdvertisementFile [ = strFilePath ]

Property Value


strFilePath String specifying the location of an XML file containing advertisement information.

The property is read/write with no default value.

Remarks

Use the AdvertisementFile property to specify the location of an XML file that contains advertisement information from which the AdRotator will randomly select an entry to display.

For deployment and security purposes, it is strongly recommended that the XML file reside within the same Web application. It is only possible to access an XML file that is located in a different application on the same site if the application has sufficient permission.

You can set this property to either:

  • an absolute path ( ex. http://aspalliance.com/shared/myAds.xml );
  • a virtual root path ( ex. ~/shared/myAds.xml );
  • or a path relative to the location of the page that contains the AdRotator ( ex. ../shared/myAds.xml ).

Use of the AdvertisementFile property is optional. An advertisement may also be set programmatically via the handler of the AdCreated event.

The XML file may contain the following attributes. Only the ImageUrl attribute, though, is required.

Attribute Description
ImageUrl The URL of the image to display.
NavigateUrl The URL of the page to navigate to when the AdRotator is clicked.
AlternateText The text to display if the image is unavailable. Some browsers display this text a tooltip.
Keyword The category used for grouping related ads.
Impressions A value that indicates how often the ad is displayed in relation to other ads in the XML file.

The AdvertisementFile must conform to the following predetermined XML format:

<?xml xmlns = "Ad Rotator Schedule" ?>
<Advertisements>
   <Ad>
      <ImageUrl>URL of image to display</ImageUrl>
      <NavigateUrl>URL of page to navigate to</NavigateUrl>
      <AlternateText>Text to display</AlternateText>
      <Keyword>Keyword used for filtering ads</Keyword>
      <Impressions>relative weight of ad<Impressions>
   </Ad>
</Advertisements>

Note the following regarding the advertisement file:

  • The XML must be well formed.
  • Only the first <Advertisements> grouping in the file will be parsed. All other groupings will be ignored.
  • ImageUrl contains an absolute or relative URL to an image file.
  • NavigateUrl contains the URL to the page to jump to when the control is clicked. If NavigateUrl is not set, HREF property is not rendered on the corresponding anchor tag in the generated page.
  • AlternateText renders as the ALT attribute of the image. This text is displayed when the image is not available. In some browsers, this text is displayed as a tool tip for the advertisement.
  • Keyword specifies the category for the advertisement that you can filter on using KeywordFilter.
  • Impressions indicates the weight of the advertisement in the rotation schedule in relation to other advertisements in the file. The larger the number, the more often the advertisement will be displayed. If the sum of all impressions in the file exceeds 2,048,000,000 - 1, the AdRotator will raise a runtime exception.

You can also include custom attributes by using custom tags in the XML file. All attribute tags are parsed from the advertisement file and the values are placed in the AdProperties dictionary, which can be used to programmatically access custom attributes.

Example

The following example demonstrates how to declaratively set the AdvertisementFile property at design time.

<asp:adrotator id = "myAds" runat = "server" advertisementfile = "myAds.xml" />

The following example illustrates how a typical XML advertisement file is formatted.

<Advertisements>

   <Ad>
      <ImageUrl>image1.jpg</ImageUrl>
      <NavigateUrl>http://www.site1.com</NavigateUrl>
      <AlternateText>Site 1 Alternate Text</AlternateText>
      <Keyword>Category1</Keyword>
      <Impressions>100</Impressions>
   </Ad>

   <Ad>
      <ImageUrl>image2.jpg</ImageUrl>
      <NavigateUrl>http://www.site2.com</NavigateUrl>
      <AlternateText>Site 2 Alternate Text</AlternateText>
      <Keyword>Category2</Keyword>
      <Impressions>80</Impressions>
   </Ad>

</Advertisements>

 Show me 

See Also

AdRotator Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph