Wednesday, March 10, 2010


Sunset Hill Articles
30
This tutorial covers the steps required to create a basic module in DotNetNuke 5x using Visual Studio 2008.
 
Start by creating a New Project
 
 
Select ASP.NET Web Application.  For this example, the module will be named CodeCamp.  Ensure that the project is saved to the path identified below.
 
 
You can delete the App_Data folder, as well as the Default.aspx and Web.config files. 
 
 
 
In the project properties under Application - add the assembly name.  This is typically companyname.modulename
 
 
In the Compile tab, change the build output path to:  ..\..\bin 
 
 
Add a refrence to the DotNetNuke.dll file in the bin folder of the DNN instance.
 
 
Set the Copy Local and Specific Version to False 
 
 
On the Web tab, ensure the start url is the IIS alias for the local instance of DNN.  Also, in Visual Studio 2008, the Project URL must point to the project folder and you must check the Override application root url as shown below.
 
 
Add a Web User Control to the project and name it View
 
 
Add the following code to the View.ascx web user control
 
ASP.NET code for View.ascx
1
2
3
4
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="View.ascx.vb" Inherits="SunsetHill.CodeCamp.View" %>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br /><br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
 
Note that the control must inherit the companyname.modulename.controlname

In the codebehind file, add the following code:
 
Visual Basic code for View.ascx.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Imports DotNetNuke
Namespace SunsetHill.CodeCamp
Partial Public Class View
Inherits DotNetNuke.Entities.Modules.PortalModuleBase
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Label1.Text = "Winnipeg Code Camp"
Me.Label2.Text = Settings("setting1")
End Sub
End Class
End Namespace
 
Build the solution - you should see a the dll file in the bin folder as shown below:
 
 
The next step is to register the module.  Logged in with a host account. select Host --> Module Definitions
 
Click the drop-down menu for Module Definitions and select Create New Module
 
Enter values as shown below.
 
 
In this basic example, we are not implimenting the portable and searchable interfaces - so we do not need to specify values for these fields or for the business controller class.
 
 
 Enter information specifying the owner of the module.

The next step is to register the controls for the module.  Click on the edit icon for the module.
  
 
 
Click Add Definition
 
 
Enter the following values:
 
 
Next, add the View control.  Click Add Module Control.
 
 
Enter the following information in the fields.
 
  
The module has now been defined.  Navigate to a pate on the site and add the module to a page.
 
 
The  module appears on the page.
 
Now, we will add a settings control.  Create a Web User Control named Settings.ascx and add the following code:
 
ASP.NET code for Settings.aspx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="Settings.ascx.vb" Inherits="SunsetHill.CodeCamp.Settings" %>
<%@ Register TagPrefix="dnn" TagName="Label" Src="/Portals/0/~/controls/LabelControl.ascx" %>
<style type="text/css">
.style1 {
width: 400px;
}
</style>
<table class="style1">
<tr>
<td>
<dnn:label id="plSetting1" runat="server" suffix=":" controlname="txtSetting1"></dnn:label>
</td>
<td>
<asp:TextBox ID="txtSetting1" runat="server"></asp:TextBox>
</td>
</tr>
</table>
 

In the Settings.ascx.vb file, add this code:
 
Visual Basic code for Settings.ascs.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Imports DotNetNuke
Namespace SunsetHill.CodeCamp
Partial MustInherit Class Settings
Inherits Entities.Modules.ModuleSettingsBase
 Public Overrides Sub LoadSettings()
If Not Settings("setting1") Is Nothing Then
Me.txtSetting1.Text = Settings("setting1").ToString
End If
End Sub
 Public Overrides Sub UpdateSettings()
Dim objSettings As New DotNetNuke.Entities.Modules.ModuleController
objSettings.UpdateModuleSetting(Me.ModuleId, "setting1", Me.txtSetting1.Text.Trim)
End Sub
 End Class


End Namespace
 
Since we're localizing this module, we need to add a Settings.ascx.resx file to the project:
 


 
Next, we have to register the Settings control.  Go to Host -->  Module Definitions and edit the module.  Then select Add Module Control
 

The Settings should be configured as illustrated below:
 
 

To access the settings, select settings from the module menu. 
 
 

 
Settings for the module can be managed here: 
 
 
This is the end of this tutorial.  I plan to expand on this tutorial in the future with information related to adding tables to your module and creating code to access the data using CodeSmith templates.
 
In the meantime, here are some useful links:
 
 
 
 
Actions: E-mail | Permalink | Comments (0) RSS comment feed |

Comments

There are currently no comments, be the first to post one.

Post Comment

Name (required)

Email (required)

Website

Enter the code shown above in the box below

Privacy Statement  |  Terms Of Use
© 2005 - 2010 Sunset Hill Solutions