DNN4.02: Quick & Dirty C# and VB Custom Modules


Disclaimer
The point of this post is to help people understand that DNN Module development can be as simple as creating an ASP.Net User Control.  There are many benefits to minding the guidelines (which at first seem complex), but in reality, the requirements met by these guidelines are a little extreme for hobbyists & smaller projects. 

I still recommend that you use the best practices and guidelines specified in DNN Custom Modules documentation (“DotNetNuke Module Developers Guide.pdf” inside the documentation package on www.dotnetnuke.com).  Learning & minding the guidelines will:
   * prepare your module for easy deployment
   * remove database dependencies
   * enable localization
   * allow importing & exporting of information between modules
   * provide context-based actions
   * personalize the UI
   * exploit the DNN Scheduler for automating processes
   * result in cleaner, properly separated code layers for extensibility.

Also, I highly recommend Daniel Egan's book “Building Websites with VB.Net and DotNetNuke 3.0”, and keep an eye out for the upcoming 2nd edition of this book. ;)

As the title says, this is quick & dirty... for a guide through using the DotNetNuke Templates in your IDE & setting up a good, not-so-quick but clean module with best practices in mind, check out my Starting New Modules post here.

Overview
Looking through Bil Simser's “DotNetNuke vs. SharePoint“ post, I realized that there is some hesitation about custom development in DNN.  As Shaun Walker mentions lower in the comments of that post,  the guides you read online and in in books typically follow pretty strict enterprise standards.  Though it's recommended, it's not necessary...

Creating a custom module is as simple as making an ASP.Net User Control.  You will use DotNetNuke's Module Definitions page to add the Module to your DNN environment.  Once this is complete, you can add instances of your module anywhere within the site, and debug from within your DotNetNuke solution.  The demo in this post will result in a simple module that displays the ModuleId in a label.

Get DNN Going on your dev box
I recommend installing DotNetNuke's full source package (solution) if you're doing any custom dnn development.  It's free, easy to install, and gives you the opportunity to debug your module, and when you need it, the dnn environment.  You can have a local DNN solution installed and ready to go in about 10 minutes.  My post to quickly guide you through this is here: DNN4.02: Create Your DotNetNuke Development Environment
.

Create the Module
   * Open your DotNetNuke solution
   * Add a folder to the DesktopModules folder of your DotNetNuke project, ex: “ShowModuleId”
   * Add a new User Control (any language) to the ShowModuleId folder, ex: "ShowModuleId.ascx"
   * Update User Control to inherit from DotNetNuke.Entities.Modules.PortalModuleBase
   * Drop a label onto the form, inside Page_Load set label text to ModuleId.ToString()
   * Compile

Install Module
   * Open DotNetNuke web, log in as host
   * Navigate to Host > Module Definitions
   * Mouse-over the context-menu of the Module Definitions module, select “Add New Module Definition”, set the fields as follows:
       - Name: uniquely identifies module in the system, ex: ShowModuleId
       - Folder Name: the name you placed your .ascx into, this is used later, type it in right, ex: ShowModuleId
       - Friendly Name: the name the module is displayed as in the module admin dialogs
       - click Update
   * Definition fields display below, type in a definition name in New Definition, ex: ShowModuleId, click Add Definititon
   * Add Control is displayed below, click to open “Edit Module Control” dialog, set fields as follows:
       - Key: anything works in this example, key is used to uniquely identify controls within a defintion
       - Title: default title of the control when added to a page
       - Source: select the folder/modulename.ascx item in the list
       - Type: View
       - click Update
   * Navigate to Home

Trying it out
To demonstrate a couple instances of your new module on the same page, do the following 2 or 3 times.
   * Select your module from the Module: dropdown in the top 'admin' panel on the page.
   * Click 'Add' to the right

When you scroll down to the module just added, you'll see that they display the ModuleId, and are treated by DNN as completely separate entities.  You can now update the DNN settings for each of these and control view & edit privileges by Role.

What's next...
Anything you can do with a User Control you can do here.  You have full programmatic access to an amazing web application framework that provides features that would be expensive and time-consuming to build onto a new application.  You have access to free & commercial 3rd party modules, many with source, that give you a head-start on just about anything you would want on a web app (and much that the web wasn't even meant for).  If you think you've got something original and you want to sell it, you can make a lot of money on sites like Snowcovered.  Like any platform, the more you work with it, the more bells & whistles you discover & take advantage of... there's no reason that you can't start slow with DNN.

Print | posted on Monday, February 20, 2006 9:08 PM

Feedback

# re: DNN4.02: Quick & Dirty C# and VB Custom Modules

left by Bil Simser at 2/21/2006 5:34 PM Gravatar
This is great stuff but one problem I have with the whole DNN module thing. Must I really have a DNN solution in order to build a module? I mean, if it's as simple as creating a UserControl, why can't I:

1. Create a new class library project
2. Add a user control
3. Add the appropriate references to the DNN assemblies
4. Upload my module as I would any new one through the Host inteface.

Both this posting and the previous one you have suggest I have to open the DNN solution (meaning I have to have one in the first place) in order to build a module.

Or am I missing something here?

# re: DNN4.02: Quick & Dirty C# and VB Custom Modules

left by Gerry at 2/22/2006 12:49 AM Gravatar
I prefer to work directly within the DNN solution, or at least have it nearby. It's free, easy to install, and it gives me the ability to debug my module as well as DNN if needed...

Your development should occur within the DNN environment; you're likely not going to write a fully functional DNN module and debug/test it by uploading it into your production environment each time.

Technically, you *could* create a new web project, add references to the DotNetNuke.dll (or add & refer to the DotNetNuke Website project, which comes in both DNN download packages), inherit the user control from PortalModuleBase, do your work and deploy the resulting files (zipped, along with the dnn manifest XML file) into a live DNN environment via the Host interface.
Title  
Name
Email (never displayed)
Url
Comments   
Please add 3 and 7 and type the answer here: