Working around some ASP.NET AdRotator limitations#

I'm playing working with the updated AdRotator in ASP.NET 2.0, and I had to work around some limitations so I figured I'd best share what I came up with...

The AdRotator is a control that shows a random advertisement, which is basically just an image and a link to a target page (like a shopping page or an e-commerce site). And that's the problem. That's all it is. An image and a link. What I wanted to do is make an advertisement that also shows a description and a price next to it, but unfortunately there's no templating mechanism for the AdRotator to customize the control. (Spot the hidden feature request.)

Another problem I had is that I pull the advertisement data from the database (the new AdRotator supports the cool new ASP.NET 2.0 databinding so you're not limited to xml files anymore like before). But there's no NavigateUrl in the database, and I need to give the AdRotator a URL to which it should navigate when you click the image. Unfortunately, I can't make the NavigateUrlField "smart". I have a ProductID in my datasource, so I'd like to have it construct a url based on that, a little something like this:

<asp:AdRotator (...) NavigateUrlField='<%# Eval("ProductID", "~/Shop.aspx?ProductID={0}") %>' />

But that doesn't work of course, the NavigateUrlField has to point to a field in the datasource (and I'm not sure if this <%# %> construct would work anyway)...

I could add a NavigateUrl field on the business tier but frankly, I don't want to. It's not the business tier's business (pun intended) to know there's an AdRotator somewhere down the line that needs this funny Shopping URL. It only knows about products. I could add the column on the client tier but then I'd lose my beautifully simple databinding since I'd need to preprocess the data. Well in fact the databinding would still be easy, I'd just bind it to a local "proxy" preprocessor object in stead of to the actual webservice. But it's less transparant and I still wouldn't have my price and description anywhere near my image...

In the end, I decided to do it a little differently. I created a simple Advertisements user control with an AdRotator in it, and labels for the price and description. Then I just use the AdRotator's AdCreated event to play around a little bit. The trick is, you can get to the data source fields through the AdProperties dictionary on the AdCreatedEventArgs. I'll just let the code speak for itself:

<%@ control language="VB" classname="Advertisement"%>
<script runat="server">
 Private Sub shopAds_AdCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AdCreatedEventArgs)
  e.NavigateUrl = "~/Shop.aspx?ProductID=" & e.AdProperties("ProductID")
  description.Text = e.AdProperties("Description")
  price.Text = e.AdProperties("Price")
 End Sub
</script>
<table>
 <tr>
  <td>
   <asp:AdRotator ID="shopAds" Runat="server" DataSourceID="advertisementData" ImageUrlField="ImageUri" OnAdCreated="shopAds_AdCreated" />
  </td>
  <td>
   <asp:Label ID="description" Runat="Server" />
   <br />
   <asp:Label ID="price" Runat="Server" />
  </td>
 </tr>
</table>
<asp:ObjectDataSource ID="advertisementData" Runat="server" TypeName="WeFly247.UI.Proxies.PassengerWebService" SelectMethod="GetProducts">
 <SelectParameters>
  <asp:ProfileParameter Name="cultureName" Type="String" PropertyName="Culture" />
 </SelectParameters>
</asp:ObjectDataSource>
Blog | Programming | .NET | ASP.NET | WeFly247 | Whidbey | Samples
Saturday, November 18, 2006 1:05:38 AM (Romance Standard Time, UTC+01:00)
I owe you a favor for this one. Using what you started, i created a series of user ad controls. Some are text only some are images only, and some are both. I use the rotator control only to handle the information from the database. THen i feed thisto the images or text. I needed to count the clicks so i needed postback.

THANKS!
KES
Saturday, November 25, 2006 12:48:32 PM (Romance Standard Time, UTC+01:00)
dsfds
Friday, December 15, 2006 11:17:08 AM (Romance Standard Time, UTC+01:00)
GOOD
Friday, December 15, 2006 11:17:29 AM (Romance Standard Time, UTC+01:00)
GOOD
Thursday, January 25, 2007 4:00:57 AM (Romance Standard Time, UTC+01:00)
TODAY I LOOK A GOOD ARCHIVES!!
Monday, January 29, 2007 11:08:33 AM (Romance Standard Time, UTC+01:00)
Good Site . Nice work.
Wednesday, February 07, 2007 6:25:43 AM (Romance Standard Time, UTC+01:00)
In the same calification we can find drugs like!
Wednesday, February 07, 2007 6:26:57 AM (Romance Standard Time, UTC+01:00)
Hello I like your page is interesting...
10/325 - Vicoprofen - Lortab- Tylenol #3- - Ativan
All Major Medications are available right here at:
Wednesday, February 07, 2007 6:29:19 AM (Romance Standard Time, UTC+01:00)
Have a great day!
Tuesday, March 06, 2007 8:09:58 AM (Romance Standard Time, UTC+01:00)
TODAY I LOOK A GOOD ARCHIVES!!
Tuesday, March 06, 2007 8:23:41 AM (Romance Standard Time, UTC+01:00)
Hello I like your page is interesting...
10/325 - Vicoprofen - Lortab- Tylenol #3- - Ativan
All Major Medications are available right here at:
Tuesday, March 06, 2007 8:25:49 AM (Romance Standard Time, UTC+01:00)
In the same calification we can find drugs like!
Tuesday, March 06, 2007 8:28:28 AM (Romance Standard Time, UTC+01:00)
Have a great day!
Comments are closed.
All content © 2008, Jelle Druyts
On this page

Recent Photos
www.flickr.com
This is a Flickr badge showing public photos from Jelle Druyts. Make your own badge here.
Advertising
Top Picks
Statistics
Total Posts: 344
This Year: 7
This Month: 0
This Week: 0
Comments: 522
Archives
Sitemap
Disclaimer
This is my personal website, not my boss', not my mother's, and certainly not the pope's. My personal opinions may be irrelevant, inaccurate, boring or even plain wrong, I'm sorry if that makes you feel uncomfortable. But then again, you don't have to read them, I just hope you'll find something interesting here now and then. I'll certainly do my best. But if you don't like it, go read the pope's blog. I'm sure it's fascinating.

Powered by:
newtelligence dasBlog 2.0.7226.0

Sign In