Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [141]

By Root 5799 0

www.microsoft.com/MSPress/books/5727.asp

Programming ASP.NET Applications

50

The root node contains multiple elements, one for each image to show. The advertisement file must reside in the same application as the AdRotator control. The syntax of the AdRotator control is as follows:

<%@ Page Language="C#" %>

Ad Rotators

Dino Esposito's Books

AdvertisementFile="MyBooks.xml" />

In the XML advertisement file, you use the node to indicate the image to load and the node to specify where to go in case of a click. The node indicates the alternate text to use if the image is unavailable, whereas indicates how often an image should be displayed in relation to other images in the advertisement file. Finally, each image can also be associated with a keyword through the node. Of all the elements, only is required.

Once per roundtrip, the AdRotator control fires the server-side AdCreated event. The event occurs before the page is rendered. The event handler receives an argument of type AdCreatedEventArgs, which contains information about the image, a navigation URL, alternate text, and any custom properties associated with the advertisement. The AdCreated event can be used to programmatically select the image to show. The XML schema of the advertisement is not fixed and can be extended with custom elements. All nonstandard elements associated with the selected advertisement will be passed to the AdCreated event handler stuffed in the AdProperties dictionary member of the AdCreatedEventArgs class.

Note

The AdRotator control can also get its advertisement feed through an XML or relational data source. Image and navigation URLs, as well as the alternate text, can be read from fields belonging to the data source. The control cannot be bound to more than one data source at a time. If more than one property—AdvertisementFile, DataSourceID, or DataSource—is set, an exception will be thrown.

The Calendar Control


The Calendar control (shown in Figure 6-5) displays a one-month calendar and allows you to choose dates and navigate backward and forward through the months of the year. The control is highly customizable both for appearance and functionality. For example, by setting the SelectionMode property, you can decide what the user can select—that is, whether a single date, week, or month can be selected.

SelectedDate="2010-08-21" VisibleDate="2010-08-21" />

Figure 6-5. The Calendar control in action.

The VisibleDate property sets a date that must be visible in the calendar, while SelectedDate sets with a different style the date that is rendered as selected. The control also fires three ad hoc events: DayRender, SelectionChanged, and VisibleMonthChanged. The DayRender event signals that the control has just created a new day cell. You can hook the event if you think you need to customize the cell output. The SelectionChanged event fires when the selected date changes, while VisibleMonthChanged is raised whenever the user moves to another month using the control’s selector buttons.

The Calendar control originates a roundtrip for each selection you make. Although it is cool and powerful on its own, for better performance you might also want to provide a plain text box for manually typing dates.

The Xml Control


The Xml control, defined by the tag, is used to inject the content of an XML document directly into an ASP.NET page. The control can display the source XML as-is or as the results of an XSL transformation (XSLT). The Xml control is a sort of declarative counterpart for the XslTransform class, and it can make use of the .NET Framework XSLT transform class internally.

You use the Xml control when

Return Main Page Previous Page Next Page

®Online Book Reader