A Custom AdRotator - Borrowing Code from The Mono Project

Sometimes in ASP.NET development you need just a little different functionality than what the built in controls have. Often you can inherit the control and extend functionality on top of the original version, but sometimes you wish you could just make a small change to the inner workings of the control. One option is to borrow the Mono implementation and modify it to meet your needs.

So today I wanted to implement an Ad Rotator so I could alternate the banner ad on mojoPortal.com to switch between my add for Event Calendar Pro and Form Wizard Pro. There is a built in AdRotator control in ASP.NET, so I read a few articles about it, here and here. In those articles they suggest click tracking by using a redirect page, but I wanted to track it in google Analytics since we already have it integrated in mojoPortal. To do this I need to add an onclick to the rendered link to call the tracking code and then navigate to the href. So an example onclick for tracking is like this:

onclick="mojoPageTracker._trackPageview('/EventCalendarProBanner.aspx');window.open(this.href,'_self');return false;"

This just tracks a made up url (/EventCalendarProBanner.aspx) before navigating to the linked product page.

The ASP.NET AdRotator control can consume an xml file in this format:

<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/images/Contoso_ad.gif</ImageUrl>
<NavigateUrl>http://www.contoso.com</NavigateUrl>
<AlternateText>Ad for Contoso.com</AlternateText>
</Ad>
<Ad>
<ImageUrl>~/images/ASPNET_ad.gif</ImageUrl>
<NavigateUrl>http://www.asp.net</NavigateUrl>
<AlternateText>Ad for ASP.NET Web site</AlternateText>
</Ad>
</Advertisements>
 

But I wanted to add another property to store my OnClick code, so my new format is like this:

<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/Data/Sites/1/skins/mojosite-brightside/eventcalpro-banner.gif</ImageUrl>
<NavigateUrl>~/event-calendar-pro-offer.aspx</NavigateUrl>
<AlternateText>A better event calendar for mojoportal</AlternateText>
<OnClientClick>mojoPageTracker._trackPageview('/EventCalendarProBanner.aspx');window.open(this.href,'_self');return false;</OnClientClick>
</Ad>
<Ad>
<ImageUrl>~/Data/Sites/1/skins/mojosite-brightside/formwizardpro-leaderboard.gif</ImageUrl>
<NavigateUrl>~/form-wizard-pro-single-installation-license-offer.aspx</NavigateUrl>
<AlternateText>Form Wizard Pro - Easy Forms for mojoPortal</AlternateText>
<OnClientClick>mojoPageTracker._trackPageview('/FormWizardProBanner.aspx');window.open(this.href,'_self');return false;</OnClientClick>
</Ad>
</Advertisements>

Since I don't really have access to the internal workings of the ASP.NET AdRotator, I decided to have a look at the source code for the Mono project implementation of this control. I downloaded the 3 files AdRotator.cs, AdCreatedEventArgs.cs, and AdCreatedEventHandler.cs, added them into my mojoPortal.Web.Controls project and changed the namespace so it wouldn't clash with the built in ASP.NET version. I had to modify a few small things where it was using some internal Mono stuff but not much. I added the OnClientClick property to AdCreatedEventArgs.cs and added on line of code to the render method of AdRotator.cs:

if (e.OnClientClick != null && e.OnClientClick.Length > 0)
w.AddAttribute(HtmlTextWriterAttribute.Onclick, e.OnClientClick);

I add it to my layout.master (Master Page) and configure it to read the xml file with my ads:

<mp:AdRotator id="ads1" runat="server" AdvertisementFile="~/App_Data/mojoads.ads" />

And voila, it works and only took about 20 minutes to implement.

 

Gravatar Joe Audette is the founder of the mojoPortal project and was the primary developer until February 2017.

ZedGraph - Easy Web Charts

Everybody likes charts, a picture tells a thousand words they say, and I'm no different, I like them too. I've had my eye on the ZedGraph project for several years and have been including their dlls with mojoPortal for a long time with the intention of using ZedGraph in mojoPortal. I don't know why it took me so long to actually use it, but I finally implemented a chart in the Site Statistics feature of mojoPortal to show the trend of site registrations. I suppose it might have taken me so long to get around to this partly because charts are not that useful unless you have a significant amount of data. This year I have definitely noticed an increasing rate of people registering on mojoPortal.com, so I thought I would like to see this on a chart. ZedGraph is so easy! It took me maybe 30 minutes total to figure out how to create my first chart. Now I'm all excited to use it in a lot of places like sales reports for the web store feature and other interesting metrics. Maybe could produce pie charts of survey results, not for text questions but for ones that have choices we could show pie charts of how many people picked the various choices. Anyway, lots of ideas where to use it!

You can see the live version of this chart on our community page:

community growth chart

Now for me this chart is very meaningful because I can see that site registration started rising after the august 2007 release of mojoPortal that included support for OpenID and Windows Live ID, having those options makes it easy for a lot of people to register becuase they don't have to have any new passwords. That rise also was probably due to the 2007 CMS Awards. Then the big increase in the trend started when I went on a mojoPortal Beautification Campaign and made about 20 new good looking skins from April 2008 to May 2008. mojoPortal.com got a makeover with a new skin in May 2008 as well. In any case, its a positive trend showing an order of magnitude in growth. I sure hope it keeps going up! We have at least another order of magnitude to go to catch up with DotNetNuke. Where we are currently getting about 250 new members per month, they get more than that per day. So I look to them to see how high it could go.  They have a lot more visibility due to all the support they have from Microsoft, and they take a more agressive approach to aquiring members by requiring site registration in order to download. I don't plan to change our approach, registration is not required to download mojoPortal, but registration is required to get support in the forums. I am looking at ways to increase our visibility in the Microsoft ecosystem. Hopefully we will be able to move to CodePlex soon for our source code and file hosting. The Codeplex Team is working on some fixes to their svn bridge that should make it possible for us to move there. I think that move will give us a lot more visibility in the .NET community.

Don't Forget Voting for the 2008 CMS Awards ends October 20

So if you haven't already please vote for mojoPortal!

vote for mojoportal in the 2008 cms awards

 

Gravatar Joe Audette is the founder of the mojoPortal project and was the primary developer until February 2017.

Content Rating System and Feed Manager Improvements

Just a quick post to mention some new goodness that has landed in the mojoPortal code repository.

Content Rating System

I just completed the first version of the Content Rating System. Its built into the core in such a way that it can be used across features. So far I've integrated it into the Html Content Mdodule and the Blog, but there are lots of other places where I plan to use it too such as for product ratings in the WebStore feature.

content rating screen shot

It has an option to also allow feedback comments:

content rating with comments screen shot

but I haven't yet implemented a UI for reviewing or showing the comments.

On this site I've configured it just for rating without comments in the blog (since it already has comments) but in the documentation pages like here, I've enabled the comments. I've got mixed feelings about it in terms of the comments because I also plan to implement a threaded comment feature that can be integrated into any of the features so that threaded dicussions can be attached to any content. When that is ready it may make this comment feature for the ratings less useful.

Feed Manager Improvements

Huge thanks to Walter Ferrari for his improvements to the Feed Manager! We now have support for Atom feeds and the really cool new feature is an option for selective publishing. With selective publishing you can subscribe the Feed Manager instance to a bunch of feeds and then selectively publish just the posts you like from those feeds.

You can try these features now on demo.mojoportal.com

I expect to make a new release of mojoPortal to include these features within days.

 

 

Gravatar Joe Audette is the founder of the mojoPortal project and was the primary developer until February 2017.

Mono 2.0!

Congrats to the Mono Team on shipping Mono 2.0!

Mono 2.0

I'm eager to try it myself and am interested to hear from people using mojoPortal on Mono. So if you try it with our latest release package for Mono, let us know how it works for you.

I generally test Mono with a virtual machine where I build Mono from svn to stay up with the latest changes and then I keep another VM for testing the releases. So I downloaded the new VMWare image with openSuse 11 and Mono 2.0, but apparently this vmware image isn't compatible with the older version of VMWare server I have running, so I've got some upgrading to do before I can try it. I have a physical machine running openSuse 10.3 with VMWare server and then I run the testing virtual machines inside it. I also got a new video card I need to install in this machine so I'm installing that first and then upgrading my vmware host machine to openSuse 11 and then I'll install the newer release of VMWare server, and then finally I will be ready to play with the new Mono release.

2.0 is a big milestone for the Mono project so I'm really looking forward to it. Hope you will try it too and share your experiences. If you are a developer and you have MonoDevelop, we include a MonoDevelop solution with the mojoPortal source code, so you can checkout mojoportal from our Subversion repository and compile it with MonoDevelop. So not ony can you run mojoPortal on Mono, you can also do mojoPortal development on Linux with MonoDevelop.

Gravatar Joe Audette is the founder of the mojoPortal project and was the primary developer until February 2017.

Tip/Trick Creating tabs in the mojoPortal Html Content Module

In the mojoPortal 2.2.7.3 release announcement, I mentioned that we changed from ExtJs tabs to YUI tabs in mojoPortal. One side benefit of this is that its now possible to create tabs in your content using the editor.

In the past this wasn't possible. I had written a .NET wrapper control around the ExtJs tabs, but only developers could use that, there was no simple way to create tabs right in your content. The integration with YUI tabs is a little looser, I have not implemented a .NET control for it yet though I may do so in the future. But the main scripts for YUI tabs are included by default, so you can paste a simple chunk of markup into the source view of the editor to get the start of your tabs, and then you can edit it from there to add more tabs or change the labels and contents of the tab.

Now you won't see the tabs in the editor, but when you save it you will see the tabs.

To try it out, add an Html Content instance to a page in your mojoPortal site or on our demo site. Click the edit link to edit the content, then click the source button to see the raw markup view. Now paste in this:

<script type="text/javascript">
var myTabs = new YAHOO.widget.TabView("demo");
</script>
<div class="yui-skin-sam">
<div id="demo" class="yui-navset">
<ul class="yui-nav">
<li class="selected"><a href="#tab1"><em>Tab One Label</em></a></li>
<li><a href="#tab2"><em>Tab Two Label</em></a></li>
<li><a href="#tab3"><em>Tab Three Label</em></a></li>
</ul>
<div class="yui-content">
<div><p>Tab One Content</p></div>
<div><p>Tab Two Content</p></div>
<div><p>Tab Three Content</p></div>
</div>
</div>
</div>

Save, and you will see something like this:

screen shot of YUI tabs

At some point when I implement content templates I will make it easy to do this by selecting a content template, but thought I would mention it for the more html savvy users.

Gravatar Joe Audette is the founder of the mojoPortal project and was the primary developer until February 2017.