Creating A DNN Module
Creating A DNN Module
Creating A DNN Module
Very important: Click once on root directory in Solution Explorer window. Doing so will ensure that starter
module code is created in proper place.
On next menu, click once on DotNetNuke Module (under My Templates), select "Visual Basic" from Language
dropdown, type "GuestBook." in Name box, and click Add.
If files DataProvider.vb, GuestBookController.vb, GuestBookInfo.vb, SqlDataProvider.vb in ModuleName
directory are under DesktopModules/App_Code then they are in wrong place. Click on ModuleName folder and
drag it under App_Code directly under main root of website. You have to move DesktopModules/ModuleName
and drag ModuleName folder so its under DesktopModules directly under main root of website. Correct way it
should look:
A very helpful help page comes up and instructs to rename /App_Code/ModuleName to /App_Code/GuestBook,
and rename /DesktopModules/ModuleName to /DesktopModules/GuestBook.
Make changes by right-clicking folder name in Solutions Explorer and selecting Rename from menu. You have
to do this twice. Once for folder under App_Code, and then for folder under DesktopModules.
Now, from toolbar, select Build, then Build Web Site:
From toolbar, select Debug, then Start Without Debugging. (see more on debugging in this post)
The website should now come up.
Click Login:
Log in as "host". Password (if you haven't already changed it) is "dnnhost":
Then EDIT and COPY.
Switch back to DotNetNuke website and paste script you copied into window, click "Run as Script" box and
click EXECUTE.
From HOST menu select "Module Definitions"
Click small down arrow in upper left hand corner of Module Definitions menu and select "Create New Module"
In the Page Details menu:
Enter "Guest Book" for Page Name.
Enter "Guest Book" for Page Title.
Enter "Guest Book" for Description.
Click the View Page box next to All Users.
Then, click Update:
If you get "Object reference not set to an instance of an object" error, click "Guest Book" link: (However, if
running DotNetNuke on machine lower than Pentium III with 512KB RAM, DotNetNuke will regularly throw
this error).
Create Table
Log into DotNetNuke website as Host (if not already logged in as Host), and from Host menu, select SQL.
Design table in table designer using graphics below. Make "ID" column an "identity" column and also set it as
PK. Save it as YourCompany_GuestBook.
Create SPs
Log into DotNetNuke website as Host (if not already logged in as Host), and from Host menu, select SQL.
Verify that SPs have been created. Switch back to VS, and select View from the toolbar and Server Explorer:
Scroll down list of SPs and verify that these SPs have been created:
YourCompany_GuestBook_Delete
YourCompany_GuestBook_GetAll
YourCompany_GuestBook_Insert
YourCompany_GuestBook_Update
Alter "SqlDataProvider.vb" file. In VS, select View from toolbar and "Solution Explorer":
In Solution Explorer, expand GuestBook directory under App_code and double-click SqlDataprovider.vb:
Replace code with:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Framework.Providers
Namespace YourCompany.Modules.GuestBook
BLL will get done fast because its only 2 files: simple class file to hold data, and "controller" file that fills class
file with data as well as handle inserting and deleting data.
BLL
To build BLL, we alter: GuestBookInfo.vb, GuestBookController.vb. And that's it! This is step thats usually
hardest for beginners to understand but is really not that complicated. However, ASP.NET 2.0 does provide a
major reduction of code over ASP.NET 1.1 version.
Alter GuestBookInfo.vb
In VS, select View from toolbar and Solution Explorer:
In Solution Explorer, expand GuestBook directory under App_code, and double-click GuestBookInfo.vb:
Replace every single line of code in the file with this code:
Imports System
Imports System.Configuration
Imports System.Data
Namespace YourCompany.Modules.GuestBook
Replace every single line of code in the file with this code:
Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.ComponentModel
Imports System.Data
Imports System.Xml
Imports System.Web
Imports DotNetNuke
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Search
Namespace YourCompany.Modules.GuestBook
Public Class GuestBookController
<DataObjectMethod(DataObjectMethodType.Insert)> _
Public Shared Sub GuestBook_Insert(ByVal objTest As GuestBookInfo)
DataProvider.Instance.YourCompany_GuestBook_Insert(objTest.ModuleId, objTest.Name, _
objTest.Email, objTest.Message)
End Sub
<DataObjectMethod(DataObjectMethodType.Delete)> _
Public Shared Sub GuestBook_Delete(ByVal objTest As GuestBookInfo)
DataProvider.Instance. YourCompany_GuestBook_Delete(objTest.ID)
End Sub
<DataObjectMethod(DataObjectMethodType.Select)> _
Public Shared Function GuestBook_GetAll(ByVal ModuleId As Integer) As List(Of GuestBookInfo)
Return CBO.FillCollection(Of GuestBookInfo)(DataProvider.Instance()._
YourCompany_GuestBook_GetAll(ModuleId))
End Function
<DataObjectMethod(DataObjectMethodType.Update)> _
Public Shared Sub GuestBook_Update(ByVal objTest As GuestBookInfo)
DataProvider.Instance. YourCompany_GuestBook_Update(objTest.ID, _
objTest.Name, objTest.Email, objTest.Message, objTest.DateEntered)
End Sub
End Class
End Namespace
Review
What did we just do? GuestBookInfo.vb was created. This is just a simple class file. It will hold data.
Change content so it matches picture below. Order does not matter. Save and close the file when done.
Change content so it matches picture below. The order does not matter. Save and close the file when done.
Double click on "ViewGuestBook.ascx.resx" to open it.
Change content so it matches picture below. The order does not matter. Save and close the file when done.
Replace code with this code (save and close file when done):
<%@ Control language="VB" Inherits="YourCompany.Modules.GuestBook.EditGuestBook"
CodeFile="EditGuestBook.ascx.vb" AutoEventWireup="true"%>
<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>
<dnn:label id="lblContent" runat="server" controlname="lblContent" suffix=":"></dnn:label>
<asp:ObjectDataSource ID="ObjectDataSource_Tasks" runat="server"
DataObjectTypeName="YourCompany.Modules. GuestBook.GuestBookInfo"
DeleteMethod="GuestBook_Delete" InsertMethod="GuestBook_Insert"
OldValuesParameterFormatString="original_{0}" OnInit="Page_Load" SelectMethod="GuestBook_GetAll"
TypeName="YourCompany.Modules.GuestBook.GuestBookController" UpdateMethod="GuestBook_Update">
<SelectParameters><asp:Parameter DefaultValue="00" Name="ModuleId" Type="Int32" /></SelectParameters>
</asp:ObjectDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource_Tasks" DataKeyNames="ID">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" Visible="False" />
<asp:BoundField DataField="ModuleID" HeaderText="ModuleID" Visible="False" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Message" HeaderText="Message" SortExpression="Message" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField ApplyFormatInEditMode="True" DataField="DateEntered" DataFormatString="{0:d}"
HeaderText="Date" HtmlEncode="False" SortExpression="DateEntered" />
</Columns>
</asp:GridView>
Right-click on "Settings.ascx" and select "View Markup":
Replace code with this code (save and close file when done):
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Settings.ascx.vb"
Inherits="YourCompany.Modules.GuestBook.Settings" %>
<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>
<dnn:label id="lblshowform" runat="server" controlname="txtshowform" suffix=":"></dnn:label><br/>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Selected="True">Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>
Right-click on "ViewGuestBook.ascx" and select "View Markup":
Replace code with this code (save and close file when done):
<%@ Control Language="VB" Inherits="YourCompany.Modules.GuestBook.ViewGuestBook"
CodeFile="ViewGuestBook.ascx.vb" AutoEventWireup="true" %>
<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>
<asp:ObjectDataSource ID="ObjectDataSource_Tasks" runat="server"
DataObjectTypeName="YourCompany.Modules. GuestBook.GuestBookInfo"
DeleteMethod="GuestBook_Delete" InsertMethod="GuestBook_Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="GuestBook_GetAll"
TypeName="YourCompany.Modules. GuestBook.GuestBookController" UpdateMethod="GuestBook_Update"
OnInit="Page_Load">
<SelectParameters><asp:Parameter DefaultValue="00" Name="ModuleId" Type="Int32" /></SelectParameters>
</asp:ObjectDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource_Tasks"
AutoGenerateColumns="False" AllowPaging="True" HorizontalAlign="Center">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Message" HeaderText="Message" SortExpression="Message" />
<asp:BoundField ApplyFormatInEditMode="True" DataField="DateEntered" DataFormatString="{0:d}"
HeaderText="Date" SortExpression="DateEntered" HtmlEncode="False" />
</Columns>
<EmptyDataTemplate>There are no entries.</EmptyDataTemplate>
</asp:GridView><br/>
<center>
<dnn:Label ID="lblAddMessage" runat="server" ControlName="lblAddMessage" Suffix=":"></dnn:Label>
</center><br/>
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource_Tasks"
DefaultMode="Insert" HorizontalAlign="Center">
<InsertItemTemplate>
<table cellpadding="2" cellspacing="5" style="width: 50%" align="center">
<tr>
<td align="right" style="width: 4px"><asp:Label ID="Label1" runat="server" Text="Name"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name")%>' Width="264px"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 4px; height: 23px">
<asp:Label ID="Label3" runat="server" Text="Email"/></td>
<td style="width: 100px; height: 23px">
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email")%>' Width="264px"/></td>
</tr>
<tr>
<td align="right" style="width: 4px; height: 21px">
<asp:Label ID="Label2" runat="server" Text="Message"></asp:Label></td>
<td style="width: 100px; height: 21px">
<asp:TextBox ID="MessageTextBox" runat="server" EnableViewState="False" MaxLength="250" Rows="2" Text='<
%# Bind("Message") %>' TextMode="MultiLine" Width="264px"></asp:TextBox></td>
</tr>
<tr>
<td align="right" colspan="2" style="height: 21px">
<asp:Button ID="InsertButton" runat="server" Text="Submit" CommandName="Insert" /></td>
</tr>
</table><br/>
</InsertItemTemplate>
</asp:FormView>
Right-click on "EditGuestBook.ascx" and select "View Code":
Replace code with this code (save and close file when done.):
Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.Entities.Modules
Namespace YourCompany.Modules.GuestBook
Partial Class EditGuestBook Inherits PortalModuleBase
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Try
Catch exc As Exception
Exceptions.ProcessModuleLoadException(Me, exc)
End Try
End Sub
Protected Sub SetModuleId(ByVal sender As Object, ByVal e As System.Web.UI.WebControls._
ObjectDataSourceSelectingEventArgs) Handles ObjectDataSource_Tasks.Selecting
e.InputParameters("ModuleId") = ModuleId.ToString
End Sub
End Class
End Namespace
Right-click on "Settings.ascx" and select "View Code":
Replace code with this code (save and close file when done):
Imports System
Imports System.Web.UI
Imports DotNetNuke
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Exceptions
Namespace YourCompany.Modules.GuestBook
Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.Entities.Modules
Namespace YourCompany.Modules.GuestBook