InstantForum.NET 2010-1 Introducing Plug-Ins

The next InstantForum.NET 2010 update will be available soon. Alongside resolving a number of issues reporting since the final 2010 release this update will introduce a new light-weight plug-in framework allowing developers to extend InstantForum.NET without having to modify the core code.

We intend to develop a number a sample plug-ins & tutorials to help plug-in developers get started. We'll also be encouraging others to develop & share plug-ins by developing a dedicated area of our web site to publish & share plug-ins as well as recognizing & rewarding the plug-in authors.

The plug-in framework has been baked directly into our InstantASP.Common framework ensuring the next update of InstantKB.NET will also support custom 3rd party plug-ins.

It's still early days however our basic goals are...

1. Provide a number of out the box sample plug-ins
2. Provide documentation & tutorials to help plug-in developers get started
3. Provide an area on our site developers can promote, publish & share plug-ins for free with others

Obviously we need to release InstantForum.NET 2010-1 before any of this can happen and you'll see an update very soon.  Stay tuned to the blog.

How do plug-ins work within InstantForum.NET 2010

A plug-in within InstantForum.NET 2010 is essentially a single DLL file (containing your plug-in code)  and any number of user controls (or .ascx) files containing your plug-ins mark-up.

As plugins are standard ASP.NET user controls you can use server controls within plug-ins (labels, links, 3rd party components etc).  You can programmatically set-up controls from your plug-ins code-behind.

Tp create a InstantForum.NET plug-in from a user control you'll need to ensure the code for the user control inherits from our InstantASP.Common.UI.Base.Plugin class and implements our InstantASP.Common.Plugins.IPagePlugin interface.

The  InstantASP.Common.UI.Base.Plugin base class derives from System.Web.UI.UserControl however it provides additional functionality to load your plug-ins control at run-time and inject your plug-in into the containing pages control collection.

To allow your plug-in to modify the containing page (for example add css or custom JavaScript or modify the containing pages control collection) you'll need to implement the InstantASP.Common.Plugins.IPagePlugin interface.

This interface provide four key events (OnPluginInit, OnPluginLoad, OnPluginPreRender, OnPluginRender) which allow you manipulate the page containing your plug-in at each of these four events.

Our plug-in framework within InstantForum.NET will always add your plug-ins user control to the end of the pages control collection. Just before the very end form tag. You can inject plug-ins into specific locations within mark-up by using a Response.Filter within your plug-in. This is demonstrated within our  Google AdSense plug-in (example below).

Ok, Enough already show me some code

In this example we'll create a very basic plug-in to display the text "Hello World" within InstantForum.NET.

First we'll need a user control to hold the mark-up / controls for our plug-in...


<%@ Control Inherits="InstantForum.Plugins.HelloWorld" %>
<asp:Label ID="lblHelloWorld" runat="server" />

In our code-behind we'll set-up our label control and populate this with the hello world text...


This code will be compiled into an assembly called "InstantForum.Plugins.HelloWorld.dll"...

Namespace InstantForum.Plugins

    Public Class HelloWorld
        Inherits InstantASP.Common.UI.Base.Plugin
        Implements InstantASP.Common.Plugins.IPagePlugin

        Public Sub New()

            ' setup plugin details
            Me.Name = "Hello World Plugin"
            Me.Author = "InstantASP Ltd"
            Me.SkinfileName = "Plugins/HelloWorld.ascx"

        End Sub

        ' method to setup controls within plugins ascx file
        Protected Overrides Sub InitializePlugin( _
        ByVal ctlSkin As System.Web.UI.Control)

            ' find the label control within our plugins .ascx file
            Dim lblHelloWorld As System.Web.UI.WebControls.Label = _
            CType(ctlSkin.FindControl("lblHelloWorld"), _

            ' update the text if we found the control
            If Not lblHelloWorld Is Nothing Then
                lblHelloWorld.Text = "Hello World!"
            End If

        End Sub

        ' page events you can use to modify the current page from the plugin

        Public Overloads Sub OnPluginInit( _
        ByVal context As InstantASP.Common.Plugins.IPagePluginContext) +
        Implements InstantASP.Common.Plugins.IPagePlugin.OnPluginInit


        End Sub

        Public Overloads Sub OnPluginLoad( _
        ByVal context As InstantASP.Common.Plugins.IPagePluginContext) _
        Implements InstantASP.Common.Plugins.IPagePlugin.OnPluginLoad


        End Sub

        Public Overloads Sub OnPluginPreRender( _
        ByVal context As InstantASP.Common.Plugins.IPagePluginContext) _
        Implements InstantASP.Common.Plugins.IPagePlugin.OnPluginPreRender


        End Sub

        Public Overloads Sub OnPluginRender( _
        ByVal writer As System.Web.UI.HtmlTextWriter, +
        ByVal context As InstantASP.Common.Plugins.IPagePluginContext) _
        Implements InstantASP.Common.Plugins.IPagePlugin.OnPluginRender

            MyBase.OnPluginRender(writer, context)

        End Sub

    End Class

End Namespace

Installing plug-ins with InstantForum.NET

For this Hello World example we'll need to simply copy the user control into a "Plugins" folder within the forum. You'll also need to pop your compiled DLL for the plug-in into the forum "Bin Directory.

Copy your plug-ins markup into the forums Plugiins folder. You can set the location to look for your .ascx file from within your plug-ins code-behind. It does not have to reside within the Plugins folder however we'll be suggesting this to keep things organized.

Copy your plug-ins DLL into the forum \bin directory...

Make InstantForum.NET aware of your plug-in.

Once you've copied your plug-in user control & DLL you'll need to let InstantForum.NET know to use your plug-in. This is very simple and will require a couple of lines of code within your InstantForum.NET web.config file.

let the .NET framework know which class to us to process our custom configuration section within the web.config...

<sectionGroup name="InstantASP.Common">
<section name="Plugins" type="InstantASP.Common.Plugins.PluginSectionHandler" />

Then add your plug-ins within the web.config as shown below...

    <Plugin type="InstantForum.Plugins.HelloWorld, InstantForum.Plugins.HelloWorld" />
</InstantASP.Common >

The "type" attribute within the Plugin element conains the full path to your plug-ins class and the plug-ins assembly name.

For example...

<Plugin type="YourNameSpace.YourClassName, YourAssemblyName" />

In our example our Hello World Class is located within the nstantForum.Plugins namespace and this is compiled into an assembly with an identical name. So our HelloWorld Plugin element reads..

<Plugin type="InstantForum.Plugins.HelloWorld, InstantForum.Plugins.HelloWorld" />

You can of course add as many plug-ins as you wish here.

Running InstantForum.NET with the Hello World plug-in...

Now we've registered the hellow world plug-in with InstantForum.NET lets take a look at the forum within a browser...

Obviously this particular plug-in is not very useful however it demonstrates the basic idea of how to develop & add plugs to the forthcoming InstantForum.NET 2010-1 update.

This hello world example simply adds our hello world plug-in to the end of the pages control collection. We'll The Google AdSense plug-in demonstrated below shows how to add controls to specific locations within a InstantForum.NET skin. 

What else is possible with plug-ins?

The short answer is virtually anything. As plug-ins are aware of the current page you can basically create a plug-in to perform any task within InstantForum.NET. For example you may wish to prompt users who have not yet registered to join your community. You may want to develop a plug-in that modifies post signatures or automatically add links to share content within the forum with multiple social bookmarking sites. The possibilities are fairly limitless.

Currently as a plug-in developer you can hook into the key four page level events (init, load, prerender, render). We do intend to extend the plug-in framework once we have matured a little to provide support for extending specific controls within both InstantForum.NET & InstantKB.NET.

The Google AdSense Plugin

One of the  samples we've been developing allows you to very quickly & easily add Google AdSense banners to your InstantForum.NET pages...

This plug-in works by providing a user control (AdSense.ascx shown below) to contain our Google AdSense JavaScript template. Tiis allows you to easily change the look & feel of your AdSense ads from a single user control.

The plug-in when installed then searches your pages for unique mark-up in this case <!--AdSense/{adsettings}-->. If the plug-in finds this string within your pages it will take the contents of the AdSense.ascx file and inject this into your page at the location of the <!--AdSense/{adsettings}-->.string.

It will then take the {adsettings} section from the string it's found within your page to determine your the client ID, height, width & format of the AdSense banner.

For example to display a 468x60 text banner you would use...

The plug-in will replace this mark-up on your forum page at run-time to display a AdSense banner based on the template within your AdSense.ascx plig-in file.

You can display different banner types by simply modifying the parameters within the string the plug-in searches for...


<%@ Control Inherits="InstantForum.Plugins.AdSense" %>
<div style="float: left; width: 100%; text-align: center; background-color: #ECEFF2; border: solid 1px #8AB4D1; padding: 20px 0px; margin: 0px 0px 12px 0px;">

    <script type="text/javascript">   <!--       google_ad_client = "{0}";       google_ad_width = {1};       google_ad_height = {2};       google_ad_format = "{3}";       google_ad_type = "text";       google_ad_channel = "2621593367";       google_color_border = "FFFFFF";       google_color_bg = "FFFFFF";       google_color_link = "0000CC";       google_color_url = "FFCC00";       google_color_text = "000000";    //-->    </script>    <script type="text/javascript"     src="">
   </script> </div>


You can download the code for the AdSense plug-in to learn how this works here

Whilst a little rough this plugin demonstrates how to inject a plug-ins mark-up within a specific location within a InstantForum.NET skin. We will be providing a complete working solution with a number of other plug-ins to help get you started once released.

Is InstantForum.NET aware of the installed plug-ins?

Yes. You can get a collection of installed plug-ins via the HttpContext.CurrentPlugins method. This is new for InstantForum.NET 2010-1 and will returna strongly typed collection of plug-ins.


We have lots of ideas for plug-ins and will be developing a number of out-the-box plug-ins you can download & use within InstantForum.NET 2010-1 or above.

As always we would welcome your comments & feedback below or contact us :)

I look forward to posting further information for you all ASAP :)

P.S. You can also expect to see much more documentation for InstantForum.NET 2010 very soon.



AdSensePlyginSample.txt AdSensePlyginSample.txt (7.00 KB, 1.6K views)
AdSenseLarge.gif AdSenseLarge.gif (76.00 KB, 1.4K views)
HelloWorldPlugin.gif HelloWorldPlugin.gif (49.00 KB, 1.3K views)

On a scale of 1-5, please rate the helpfulness of this blog entry

Not Helpful
Very Helpful
Optionally provide your comments to help us improve this blog entry...

Thank you for your feedback!

Add Your Comments

Comments require login or registration.