aDEFWEBSERVER
Los Angeles, CA *  Webmaster@ADefWebserver.com

Creating a DotNetNuke® Module For absolute beginners!
For DotNetNuke Version 4 - Page 6 (Page 5)

The Presentation Layer (UI)

From this point on the files that need to be altered reside in the ".../DesktopModules/GuestBook" directory.

To build the Presentation Layer we will:

And that's it! The module will then be complete.

Alter The Localization Files

Localization allows you to create labels that can have their text changed (for example to change them from English to Spanish) by simply changing a "resource" file that has a ".resx" extension.

 
Double click on "EditGuestBook.ascx.resx" to open it.
Change the content so it matches the picture on the right. The order does not matter. Save and close the file when done.
Double click on "Settings.ascx.resx" to open it.
Change the content so it matches the picture on the right. The order does not matter. Save and close the file when done.
Double click on "ViewGuestBook.ascx.resx" to open it.
Change the content so it matches the picture on the right. The order does not matter. Save and close the file when done.

Alter The Controls

The module consists of 3 controls (and their "code beside" files)

  • EditGuestBook.ascx
    • EditGuestBook.ascx.vb
  • Settings.ascx
    • Settings.ascx.vb
  • ViewGuestBook.ascx
    • ViewGuestBook.ascx.vb

(A screen shot from the module definition
that was created in the DotNetNuke site
in the early step of the tutorial.
)

Right-click on "EditGuestBook.ascx" and select "View Markup".
Replace all the code with this code (Save and close the 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>
&nbsp;
<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>
&nbsp;
<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 all the code with this code (Save and close the 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="lblshowform" 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 all the code with this code (Save and close the 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>
&nbsp;
<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"></asp:Label></td>
<td style="width: 100px; height: 23px">
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' Width="264px"></asp:TextBox></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 />
&nbsp;
</InsertItemTemplate>
</asp:FormView>

Right-click on "EditGuestBook.ascx" and select "View Code".
Replace all the code with this code (Save and close the 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 all the code with this code (Save and close the file when done.):  

Imports System
Imports System.Web.UI
Imports DotNetNuke
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Exceptions
Namespace YourCompany.Modules.GuestBook
Partial Class Settings
Inherits ModuleSettingsBase
Public Overrides Sub LoadSettings()
Try
If (Page.IsPostBack = False) Then
If (Not (CType(TabModuleSettings("showform"), String)) Is Nothing) Then
Me.DropDownList1.SelectedValue = CType(TabModuleSettings("showform"), String)
End If
End If
Catch exc As Exception
Exceptions.ProcessModuleLoadException(Me, exc)
End Try
End Sub

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim objModules As ModuleController = New ModuleController
If (Me.DropDownList1.SelectedValue = "Yes") Then
objModules.UpdateTabModuleSetting(TabModuleId, "showform", "Yes")
Else
objModules.UpdateTabModuleSetting(TabModuleId, "showform", "No")
End If
End Sub
End Class
End Namespace

 
Right-click on "ViewGuestBook.ascx" and select "View Code".  
Replace all the code with this code (Save and close the 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 ViewGuestBook
Inherits Entities.Modules.PortalModuleBase
Implements Entities.Modules.IActionable
Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
Get
Dim Actions As New Entities.Modules.Actions.ModuleActionCollection
Actions.Add(GetNextActionID, Localization.GetString(Entities.Modules.Actions.ModuleActionType.EditContent, LocalResourceFile), Entities.Modules.Actions.ModuleActionType.EditContent, "", "", EditUrl(), False, Security.SecurityAccessLevel.Edit, True, False)
Return Actions
End Get
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Try
Dim objModules As ModuleController = New ModuleController
If Not Page.IsPostBack Then
If (Not (CType(Settings("showform"), String)) Is Nothing) Then
If (CType(Settings("showform"), String) = "No") Then
' Do not allow messages to be added
FormView1.Visible = False
lblAddMessage.Visible = False
End If
End If
Else
Me.GridView1.DataBind()
End If
Catch ex As Exception
Exceptions.ProcessModuleLoadException(Me, ex)
End Try
End Sub

Protected Sub NewItem(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInserting
e.Values.Item("ID") = 0
e.Values.Item("ModuleId") = ModuleId.ToString()
e.Values.Item("DateEntered") = DateTime.Now.ToShortDateString
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

 

Review

  • Data Access Layer (DAL) (Done)
  • Business Logic Layer (BLL) (Done)
  • Presentation Layer (UI) (Done)

 

 

Build The Site

From the Toolbar select BUILD then "Build Web Site"

The site should build with no errors.
From the toolbar select DEBUG then START WITHOUT DEBUGGING
The website will come up. Click "Guest Book" on the menu bar.
The Module will now show.
   
   
   
   

BACK
 

Next: Object Data Sources Explained

 

   
   
   
DotNetNuke MarketPlace

(C) by Michael Washington - ADefWebserver.com - Webmaster@ADefWebserver.com

DotNetNuke® is a registered trademark of Perpetual Motion Interactive Systems Inc.