ASP.NET Web Controls Adrotator and its events

3:22 AM Posted by Isha

In asp.net adrotator webcontrol is a control used to control the ads n the web page.

Properties of the AdRotator control

Along with the properties that are inherited from the System.Web.UI.Control base class, the AdRotator control has three additional properties:
  1. AdvertisementFile
  2. KeywordFilter
  3. Target

AdvertisementFile

The AdvertisementFile property in asp.net represents the path to an Advertisement file. The Advertisement file is a well-formed XML document that contains information about the image to be displayed for advertisement and the page to which a user is redirected when the user clicks the banner or image. The following is the syntax of the Advertisement file:

URL of the image to display
  1. URL of the page to navigate to
  2. Text to be displayed as ToolTip
  3. keyword used to filter
  4. relative weighting of ad

Note The Advertisement file must be a well-formed XML document, as the AdvertisementFile property of the AdRotator control needs to be set to an XML file.

The following are the different elements used in the Advertisement file:

ImageUrl: Specifies an absolute or relative URL to an image file that presents the image for the advertisement. This element refers to the image that will be rendered in a browser.

NavigateUrl: Specifies the URL of a page to navigate to, if a user clicks the advertisement image. If this parameter is not set, the ad is not "live." Although this parameter is optional, it must be specified, because the ad must direct clients to a target URL when it is clicked.

AlternateText: Is an optional parameter that specifies some alternative text that will be displayed if the image specified in the ImageUrl parameter is not accessible. In some browsers, the AlternateText parameter appears as a ToolTip for the ad.

Keyword: Is an optional parameter that specifies categories, such as computers, books, and magazines that can be used to filter for specific ads.

Impressions: Is an optional parameter that provides a number that indicates the weight of the ad in the schedule of rotation relative to the other ads in the file. The larger the number, the more often the ad will be displayed.

Keyword Filter

The KeywordFilter property of active server pages dot net specifies a category filter to be passed to the source of the advertisement. A keyword filter allows the AdRotator control to display ads that match a given keyword. This enables the AdRotator control to display more context-sensitive ads, where the context is specified in the ASPX page containing the AdRotator control. When you use a keyword filter, three conditions arise:

Both the KeywordFilter and AdvertisementFile properties are set. In such a case, the AdRotator control renders the image that matches the keyword specified.

The AdvertisementFile property points to a valid Advertisement file, and the KeywordFilter property specifies a keyword that matches no images. In such a case, the control renders a blank
image, and a trace warning is generated.

The KeywordFilter property is empty. In such a case, keyword filtering will not be used to select an ad.

Target

The Target property specifies the name of the browser window or frame in which the
advertisement needs to be displayed. This parameter can also take any of the HTML frame-related keywords, such as the following:
  1. top: Loads the linked document into the topmost window.
  2. blank: Loads the linked document into a new browser window.
  3. self: Loads the linked document in the same window.
  4. parent: Loads the linked document in the parent window of the window that contains the link.
  5. After looking at the properties, let's understand the events associated with the AdRotator
  6. control.

Events of the AdRotator control

The AdRotator control supports the adCreated event that you can handle to monitor the activities of a user or a session. The adCreated event is generated with every round trip to the server, after the AdRotator control is created but before the page is rendered in the browser.

The event handler for the adCreated event is OnAdCreated and has the following syntax:

OnAdCreated (sender as Object, e as AdCreatedEventArgs)

The event handler takes two parameters. The first parameter represents the object that raises the event. The second parameter represents the AdCreatedEventArgs object that contains the data related to this event. The AdCreatedEventArgs object has a set of properties that provide information specific to the AdCreated event:

AdProperties: Is an IDictionary type object that provides all the advertisement properties that have been set for the currently selected advertisement.

AlternateText: Is a String type value that sets the ALT property of the image that is sent to the browser. In some browsers, this text is displayed as a ToolTip when the mouse cursor hovers over the image.

ImageUrl: Is a String value that sets the URL of the image that is displayed in the AdRotator control.

NavigateUrl: Is a String type value that specifies the URL of the Web page to navigate to when a user clicks the advertisement.

The OnAdCreated event handler can be used to select ads in a local code or to modify the rendering of an ad selected from the Advertisement file. If an advertisement file is set, the parameters of the AdCreated event handler are set to the selected ad when the event is generated. The source image that is specified by the Advertisement file is sized by the browser to the dimensions of the AdRotator control, regardless of the image's actual size. The ad is selected based on impressions weighting from the file.

If the values are not set in the Advertisement file, the developer can modify the values in the ImageUrl, NavigateUrl, and AlternateText properties to modify the rendering of the AdRotator control. A very common use of this is when developers need to populate the event arguments with values pulled from a database.

Rendering ads to client browsers using AdRotator

The following code uses the AdRotator server-side control to render ads to the client browsers. The AdRotator control uses an Advertisement file named Ads.xml.

<%@ Page Language="VB" %>

The following code describes the Ads.xml file that is used by the AdRotator control. The file contains two advertisements that will be dynamically shown to different users. The first ad points to an image file named Saturn.gif. When users click this image, they are directed to the Saturn Web site. The second ad points to the image named Moon.jpg.

Related Posts:

asp.net table controls and events
forms in asp.net part one two and three
asp.net introduction and application creation

0 comments:

Post a Comment