My First C# DotNetNuke Module

 

First, I create a private assembly with the Default Namespace and Assembly Name of MSquaredWeb.HelloWorld.

 

 

Then, I added a new text file to the project and renamed it HelloWorld.ascx. In the HTML of the HelloWorld file and added the following:


<%@ Control Language="c#" AutoEventWireup="false" Codebehind="HelloWorld.ascx.cs" Inherits="MSquaredWeb.HelloWorld.HelloWorld" %>

 

After saving the update, the VS IDE adds the HelloWorld.ascx.cs file to the project. In the design view of the User Control I added a label control.


<asp:Label id="lblHelloWorld" runat="server"></asp:Label>

Next, I modified the code-behind to look like the following:

 

      public class HelloWorld : PortalModuleBase

       {

              protected System.Web.UI.WebControls.Label lblHelloWorld;

 

              private void Page_Load(object sender, System.EventArgs e)

              {

                     StringBuilder sbHello = new StringBuilder();

                     sbHello.Append("Hello World!! Here is some info on the    control:<br>");

                     sbHello.Append("<B>ModuleId:</b> " + this.ModuleId + "<br>");

                     sbHello.Append("<B>PortalId:</b> " + this.PortalId + "<br>");

                    

                     lblHelloWorld.Text = sbHello.ToString();

              }

              //Web Form Designer generated code

      }

 

Note the deriving from the PortualModuleBase class. This base class provides the ModuleId and PortalId properties that I invoke the gets on.

 

Now, I go to add the control via the Host manager. First, I will debug the code via the F5 key to access the DotNetNuke portal and I get the following:

 

 

A quick look in the web.config file shows that the compilation element’s debug attribute was set to false: <compilation debug="false" />. I changed the attribute to true and the app will build and debug.

 

When the build completes and the DotNetNuke portal home page is loaded into the web browser, I login with the host account (User Name: host and Password: host) and add and new tab (page) by selecting Add link in the Page Functions area. I provided the Page Name, Title, and Description as New Tab (page). It is a good idea to change the host account password by selecting the SuperUser Account link after logging in.

 

Then, from the Host drop down list, I select Module Definitions and then the Add New Module Definition link. In the Module Name and Description fields I typed MSquaredWeb.HelloWorld and selected the Update link.

 

Then the New Definition text box is available. I enter MSquaredWeb.HelloWorld in the New Definition textbox and select the Add Definition link.

 

This exposes the Add Control link. I select the Add Control link and am presented the Edit Module Control. I enter the Title, select the Source by browsing to the user control that was created earlier, select the Type as View and then select the Update link.

 

 

This adds the Hello World module view.

 

Next, I select the new tab that I created, click on the Module drop down list, and select the MSquaredWeb.HelloWorld module and then select the Add link to add the module to the new tab.

 

 

And here it is a new module C# added to my DotNetNuke portal.

 

 

Finally, I logout and select the new tab from the menu and the new custom module is present in the page.