New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.

Creating Testable Modules - The LinksView Control

This article is cross-posted from my personal blog.

In previous blog posts in this series on creating testable modules I have shown how the various layers of a DotNetNuke module can be built and tested independently.  In this blog I will create the LinksView UserControl and demonstrate in the browser that everything does indeed work as expected.

The LinksView UserControl

Lets first take a look at the code file for the UserControl.  As we would expect the UserControl has to implement the ILinksView interface.  As we are writing a DotNetNuke Module it must also implement the IModuleControl interface.  In DotNetNuke 5.0 the IModuleControl interface replaces the PortalModuleBase class as the contract which all module controls must implement.

Listing 1 – The LinskView UserControl’s Code File

   1:  public partial class LinksView : ModuleUserControlBase, ILinksView
   2:  {
   3:      LinksViewPresenter presenter;
   5:      public LinksView()
   6:      {
   7:          //Instantiate associated Presenter
   8:          presenter = new LinksViewPresenter(this, 
   9:                      new LinksRepository(new DataService()));
  10:      }
  12:      public int ModuleId
  13:      {
  14:          get { return this.ModuleContext.ModuleId; }
  15:      }
  17:      public List Links
  18:      {
  19:          set
  20:          {
  21:              grdLinks.DataSource = value;
  22:              grdLinks.DataBind();
  23:          }
  24:      }
  26:      protected override void OnLoad(EventArgs e)
  27:      {
  28:          base.OnLoad(e);
  29:          presenter.OnViewLoaded();
  30:      }
  31:  }


In this case as we are creating a UserControl we can inherit from the new ModuleUserControlBase.  The View has to create an instance of the LinksViewPresenter, which in turn requires an instance of LinksRepository and an instance of DataService, and this is all wired up in the Constructor. 

The ModuleId property, which the presenter uses, wraps the ModuleId property of the IModuleControl’s ModuleContext property, while the Links property wraps the DataSource property of a DataGrid control on the ascx page.  Finally, the view’s OnLoad method calls the presenter’s OnViewLoaded method to make everything work.  This is similar to how we wired up the concrete View control in our HelloWorldMVP application.

Listing 2 - The LinskView UserControl’s ASCX File

   1:  <asp:DataGrid ID="grdLinks" runat="server" AutoGenerateColumns="false" 
   2:                  GridLines="None" ShowHeader="false">
   3:      <Columns>
   4:          <asp:TemplateColumn>
   5:              <ItemTemplate>
   6:                  <asp:HyperLink 
   7:                      ID="lnkLink" runat="server" CssClass="CommandButton" 
   8:                      NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"LinkUrl") %>' 
   9:                      Text='<%# DataBinder.Eval(Container.DataItem,"LinkText") %>'
  10:                      ToolTip='<%# DataBinder.Eval(Container.DataItem,"Title")%>' />
  11:              ItemTemplate>
  12:          asp:TemplateColumn>
  13:      Columns>
  14:  asp:DataGrid>


Listing 2 shows the ascx file for the UserControl.  Here we just set up the binding to the various properties of our Link objects.

Registering the LinksMVP Module

We are now ready to Register the Links MVP module.  The process has changed a little in DotNetNuke 5.0. In Host/Module Definitions (or Host/Extensions) select the Create New action.  On the first page of the Create new Extension Wizard fill out the Package level properties (Figure 1) – Note:  if you launched the Wizard from the Module Definitions page (Rather than Extensions) you will not see the Select Extension Type drop-down.

Figure 1 – Creating the New Module Definition – Page 1

The next Wizard page will allow you to set the Module properties. (Figure 2).

Figure 2 – Creating the New Module Definition – Page 2

Finally, on the last Wizard page, if you intend this module for distribution, you can add some information about you or your company (Figure 3).

Figure 3 – Creating the New Module Definition – Page 3

After selecting Next the Module will be registered.  You will need to add the Module Definition and the Module Control reference.  This is done in much the same way as it was prior to 5.0.

Setting up the Database

The last step is to create the database objects we will need.  We will do this by executing the same SQL we used in our DataService tests.

Listing 3 – The TSQL required to create the Links Table and GetLinks Procedure

   1:  CREATE TABLE {databaseOwner}[{objectQualifier}LinksMVP_Links](
   2:      [LinkId] [int] IDENTITY(1,1) NOT NULL,
   3:      [ModuleId] [int] NULL,
   4:      [LinkText] [nvarchar](250) NULL,
   5:      [LinkURL] [nvarchar](1000) NULL,
   6:      [Title] [nvarchar](250) NULL
   7:      CONSTRAINT [PK_{objectQualifier}LinksMVP_Links] PRIMARY KEY CLUSTERED ([LinkId] ASC)
   8:  )
  10:  CREATE PROCEDURE {databaseOwner}[{objectQualifier}LinksMVP_GetLinks]
  11:            @ModuleId int
  12:  AS
  13:      SELECT *
  14:      FROM {databaseOwner}{objectQualifier}LinksMVP_Links
  15:                     WHERE ModuleID = @ModuleID
  16:  GO

Add the Module to a Page

Once the Module is registered and the Database obejcts have been created we can add an instance of our new module to a test page.  As there is no data we will not see anything, but we can use SQL Server Management Studio to add some links to the database.

Figure 4 – Adding Data to the Links Table


After adding links to the table, we can refresh the page and we should see a list of the links (Figure 5)

Figure 5 – The LinksMVP Module with two Links


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

Comment Form

Only registered users may post comments.


Aderson Oliveira (22)
Alec Whittington (11)
Alessandra Davies (3)
Alex Shirley (10)
Andrew Hoefling (3)
Andrew Nurse (30)
Andy Tryba (1)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (37)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Bogdan Litescu (1)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (213)
Chris Paterra (55)
Clint Patterson (108)
Cuong Dang (21)
Daniel Bartholomew (2)
Daniel Mettler (181)
Daniel Valadas (48)
Dave Buckner (2)
David Poindexter (12)
David Rodriguez (3)
Dennis Shiao (1)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (80)
Francisco Perez Andres (17)
Geoff Barlow (12)
George Alatrash (12)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (274)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Kelly Ford (4)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matt Rutledge (2)
Matthias Schlomann (16)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Miguel Gatmaytan (3)
Mike Horton (19)
Mitchel Sellers (40)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Oliver Hine (1)
Patricio F. Salinas (1)
Patrick Ryan (1)
Peter Donker (54)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Sacha Trauwaen (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott Schlesier (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Steven Fisher (1)
Timo Breumelhof (24)
Tony Henrich (3)
Torsten Weggen (3)
Tycho de Waard (4)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (40)
Will Strohl (180)
William Severance (5)
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out