Today, we will discuss about Create a DotNetNuke (DNN) module with an .ascx control. Without the utilization of the visual studio templated of the Dotnetnuke starterkit.

Installed on the PC :

  • Visual Studio 2008 Express
  • IIS 5.1
  • Dotnetnuke
  • SQL Server 2008 R2

Dotnetnuke is arranged and acting as the default site as http:\\localhost. I utilize XP Pro IIS administrator to switch between sites.

Create a visual studio project

  • Create an C# ASP.NET Web application project
    The location of the project can be inside the DotNetNuke folder in the \DesktopModules folder. I have used “TestProject”.
  • The output of the project can be directed into the bin folder of the DotNetNuke folder. You can enter ‘..\..\bin’ as the output path in the build tab of the project properties
  • Add a reference to the DotNetNuke.dll (located in the \bin folder)
  • Add a new Web User Control (.ascx) file to your project (e.g. WebUserControlTest.ascx)
  • In the code behind of the new control, use the DotNetNuke namespaceusing DotNetNuke.Entities.Modules;
  • Inherit your control from DotNetNuke’s PortalModuleBase class. In the class created by visual studio you can replace ‘System.Web.UI.UserControl’ by ‘PortalModuleBase’. It will look like this:public partial class WebUserControlTest: PortalModuleBase
  • Implement some sample code inside the control.
    For example, add a literal component to the control, and set the Text in the ‘Page_Load’ function of the code behind.
    The .ascx file looks like this:
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControlTest.ascx.cs" Inherits="SecondTest.WebUserControlTest" %>
    <asp:Literal ID="PageHeaderText" runat="server" />The .ascx.cs file looks like this:using System;
    using System.Collections.Generic;
    using System.Linq;using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using DotNetNuke.Entities.Modules;

    namespace TestProject
    {
    public partial class WebUserControlTest : PortalModuleBase
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (this.Page.IsPostBack == false)
    {
    this.PageHeaderText.Text = "Hallo DotNetNuke world!!!";
    }
    }
    }
    }
  • Build the user control project. A DLL called ‘TestProject.dll’ will be created in the \bin folder

Notes: The web control can't contain a Form. Since Dotnetnuke as of now has structure on its parent .aspx page. Asp.net can just have one structure for every page. In this way, how about we utilize Panels, Views or Multiviews in your web control.

Create a module definition in DotNetNuke

  • Login in with a SuperUser account (host)
  • On the host page, go to module definitions
  • If you are in Edit mode, you’ll find an option ‘create new module’ at the bottom of the page.
  • For ‘Create module from”, select ‘control’ (I guess….)
  • Then in the module folder, select the folder you made for your project. I looks like DNN scans for folder in the DesktopModules folder. In this example it is ‘TestProject’.
  • When the module folder is chosen, the resource if filled in by DNN: WebUserControlTest.ascx
  • Enter a module name: E.g. ‘TestModule’
  • Enable the creating of a test page if you want.
  • Click on ‘create module’ and DNN updates it’s administraion and create a page with our new module already inside it. You need to see the text “Hallo DotNetNuke world!!!” on the page.

If there should arise an occurrence of issues. Check the security settings inside IIS. Permit script to run in the home direcorty. Furthermore let the new organizer of the venture be adjusted by the Asp.net machine account and the web visitor account (in the event that you need to test if from an alternate machine in your LAN).

Debug your control

  • In the Web settings of the project, set http://localhost/ as the Start Url.
  • Enable the use of the local IIS server and configure the following:
  • project url: http://localhost/DesktopModules/TestProject
  • Override appliucation root URL: http://localhost/
  • Go to the C# code behind of the control and set a break point at the line where we set the Text of the literal.
  • Start debugging (press F5)
  • A browser will be started, and the DotNetNuke start page is loaded.
  • Navigate to the test page of the ‘TestProject’ module. Maybe you have to login for this.
  • At the moment, the test page is loaded, visual studio express will become active and display the location where it has stopped. Now you can step through the code of your control.

You' can get an error message that your framework can't begin debugging on the web server. It likewise says you have to empower incorporated Windows verification for that. I replicated the data how to do that:

To enable integrated Windows authentication

  • Click Start and then click Control Panel.
  • In Control Panel, double-click Administrative Tools.
  • Double-click Internet Information Services.
  • Click the DotNetNuke Web server node.A Web Sites folder opens underneath the server name.
  • You can configure authentication for all Web sites or for individual Web sites. To configure authentication for all Web sites, right-click the Web Sites folder and then click Properties. To configure authentication for an individual Web site, open the Web Sites folder, right-click the individual Web site, and then click Properties.The Properties dialog box is displayed.
  • Click the Directory Security tab.
  • In the Anonymous access and authentication control section, click Edit.The Authentication Methods dialog box is displayed.
  • Under Authenticated access, select Integrated Windows authentication.
  • Click OK to close the Authentication Methods dialog box.
  • Click OK to close the Properties dialog box.
  • Close the Internet Information Services window.