Total votes: 0
Print: Print Article
Please login to rate or to leave a comment.
Published: 17 Jan 2007
This article explains how to make changes to DotNetNuke modules varying their look-and-feel as well as adding some fundamental behavior.
DotNetNuke is shipped with a number of feature-rich modules suitable for various tasks. However a necessity to modify a module’s behavior may arise. This article covers how to easily modify DNN modules and extend their behavior. To understand the article easily I recommend that you download the article code.
As a case in point, we will make minor modifications to the
Blog module step by step But first let us clarify DotNetNuke's basic structure.
DotNetNuke module structure
In DNN 4.x a module is usually comprised of front-end controls (in *.ascx files) and module’s logic (*.dll assemblies). A module’s front-end is located under DesktopModules\<Module_Name>\ folder. The assemblies files can be found in Bin\ folder.
Due to the need of an entire recompilation, modifying a module’s *.dll file is a complicated task. So we will insert all additional behavior into *.ascx files and will deal with them through the rest of the article.
Step 1: Removing needless parts
Some information displayed in a module may be redundant and should better be hidden. For example the calendar in a blog archive view is needless if posts aren’t made often. The below code will remove the calendar from the Blog archive.
Take a look at the contents of Archive.ascx file (in the DesktopModules\Blog folder). It describes how the archive view looks. Several lines in the beginning of the file contain definitions for unwanted items:
However we cannot simply remove
calendar controls since they are referred to in the underlying dll’s. Instead we should set their
visible attribute to false:
This will make a module contain only what is desired and nothing more.
Step 2: Rearranging existing controls
Let us now draw attention to the search box of the Blog module. Say we want the
dropdown at the top to be hidden and the radio buttons to be arranged vertically.
Here we need to modify the Search.ascx file. Hiding the dropdown is the same as in Step 1. Arranging the radio buttons vertically is not harder we just set
repeatdirection property of the
radiobuttonlist control to
Please note that changes to the visual style of a module (e.g. fonts, colors, etc.) are made through module.css style sheet.
Step 3: Adding logic to a module
So far we have dealt only with visual modifications to modules. But what if it’s necessary to add some new functionality to a module? We will add the total number of posts in a given month to the
Blog Module. While I would highly recommend that you do this through the code files, we’ll actually do it via the ascx control.
For example let us make blog archive show the number of posts for each month.
In order to get the number of posts made in a particular month a
SQL query should be executed. Since inline querying is forbidden in
DotNetNuke we need to create an appropriate
Storedprocedure which will return the desired count.
A stored procedure can be created by the means of the
DotNetNuke SQL tool. Open it with Host > SQL menu item. Then paste the
Storedprocedure creation query, select
Run as Script and click
storedprocedure to retrieve the number of posts for a specific month can be downloaded with the sources for the example.
storedprocedure is not the only thing we need do. In order to execute it we need to provide the proper connection settings and procedure parameters. Connection settings can be retrieved by static methods of the corresponding
DataProvider subclass. Other parameters depend on the specific case, for example portal ID can be obtained via
PortalId property of a module’s front-end control.
Anyway we will need to embed server scripts with additional logic into *.ascx controls. Here is how it would look for our example:
storedprocedure used is
Blog_GetEntriesCountForMonth and it is called with the
SqlHelper.ExecuteReader static method. Here we use standard ASP.NET notation
<%#expression%> to embed calculated values into the markup.
DotNetNuke is an open-source framework making it possible to modify the behavior of all of its parts including native and new modules. Throughout this article we have addressed questions of making changes to modules by modifying their *.ascx front-end files. Such changes do not require recompilation of underlying dll’s though they may contradict standard the DotNetNuke programming model. Anyway if a minor change to a module should be made then modifying module’s *.ascx files is the easiest way to.
The example improvements to the
Blog module can be found in the downloads section of my website. Or just click here for direct access.
Oleg Zhukov, born and living in Russia is Lead Engineer and Project Manager in a company which provides business software solutions. He has graduated from Moscow Institute of Physics and Technology (MIPT) (department of system programming) and has got a M.S. degree in applied physics and mathematics...
This author has published 5 articles on DotNetSlackers. View other articles or the complete profile here.
You might also be interested in the following related blog posts
Issue 50 - DotNetNuke 5 Admin Modules Access, Reset Logins, iPhone OWS
How to Limit Access to Administrator Modules in DotNetNuke 5 - 5 Videos
How to Create an iPhone App with OWS - 4 Videos
Performance Gains and Enhanced HTML-like Support Brought to WinForms Applications with Q3 2009 Release
Beta Testers Wanted: DotNetNuke 5.2.0 Beta Now Available
DotNetNuke 5.1.4 Released
DotNetNuke 5.1.3 Released
DotNetNuke 5 Quick Start Guide - 6 Free Videos
How to Install a Module in DotNetNuke 5 - Free Video
Issue 48 - DotNetNuke 5 Introduction and Open Web Studio Tutorials
Please login to rate or to leave a comment.