A Few New Tutorials

Just a quick post to mention a few new tutorials for mojoPortal.

How To Filter Out Un-Wanted Content From Feed Manager

by Walter Ferrari of Abertech. Big thanks to Walter! He not only helped with major improvements to the Feed Manager recently but also is willing to help with documentation which is much appreciated.

CSS - Its All About Understanding Selectors

an article I wrote today to demystify CSS a little for those trying to learn how to skin mojoPortal. Once you master CSS Selectors it becomes much easier.

Enjoy!

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

Hello World mojoPortal Quick Start Code

Just completed a new documentation page to help developers get going quickly with mojoPortal.

Hello World - Developer Quick Start

The article has a zip with sample code you can drop in and start hacking on with a few simple steps as indicated in the article. It shows how you can use a plain old UserControl or a UserControl that inherits from SiteModuleControl. Both examples also illustrate the use of the ASP.NET UpdatePanel for ajax postbacks.

Enjoy!

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

Lowering Entry Point Barriers for Developers

I'm always interested to hear developer opinions about mojoPortal. I don't always agree with them, but I try to keep an open mind and see their perspective. So I monitor the blogosphere with google alerts, so that if anyone mentions mojoPortal in their blog I get an email alert with a link. It doesn't catch everything and more often than not I just get alerts about my own blog posts, but now and then something of interest appears.

So I got an alert about this blog post by Artem Smirnov where he complained about having to inherit from a base class to make a mojoPortal plug in. He wishes he could just use a plain old UserControl and he does not want to have to create any configuration file to install it.

mojoPortal provides a base class, SiteModuleControl which "is a" UserControl that contains some additional functionality that allows you to make multi instance features. Like a blog for example, in mojoPortal you can put an instance of the blog feature on one page and another instance on another page and these are totally separate instances with different content. This is the way most of the features in mojoPortal work and SiteModuleControl provides the instance specific properties and settings that enable easy development of features that support multiple intances.

But maybe sometimes you don't need your feature to support multiple instances and would rather just use a plain old UserControl. This is the valid point I took from Artem's post. And since SiteModuleControl "is a" UserControl and plugs in the same way you plug in a UserControl, I thought, why not make it possible to use a plain old UserControl if you want to. Its a very simple code change to support it, the only thing we do differently if the UserControl is a SiteModuleControl is set a few properties on it, if its just a plain UserControl we skip that step.

Control c = Page.LoadControl(module.ControlSource);
if (c == null) { continue; }

if (c is SiteModuleControl)
{
SiteModuleControl siteModule = c as SiteModuleControl;

siteModule.SiteId = siteSettings.SiteId;
siteModule.ModuleConfiguration = module;
parent.Controls.Add(siteModule);
}
else if(c is UserControl)
{
parent.Controls.Add(c);
}

This change is in svn trunk now. I would also like to mention that you can easily install a SiteModuleControl or a UserControl right from the Web UI, you don't have to create configuration files to install it though there is a system for it and it is recommended if you will be packaging your feature for installation on other machines. The place where you can install it from the UI is under Administration Menu > Advanced Tools > Feature Installation

So, it is now possible to use a plain old UserControl if you want to. If you need to support multiple instances of your feature like we do for most of the mojoPortal features then you should inherit your UserControl from SiteModuleControl and follow the guidelines for feature development.

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

mojoPortal 2.2.7.6 Released

I'm happy to announce the release of mojoPortal 2.2.7.6, available now on the download page.

In addition to bug fixes for things reported in the forums since the last release, this release includes the new Content Rating System and Feed Manager improvements mentioned in this previous post, as well as the new option in Site Statistics to show a graph of new site member registrations that I mentioned in this post.

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

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.