phdcc.CodeModule DNN module
  search
Powered by FindinSite-MS
Write your own VB or C# code
DotNetNuke private assembly (PA) zip files: Free Download: v01.01.05, 6 February 2014. VB + DLL.
Retail version (US$10): v01.02.03, 6 February 2014. Full VB source.
Versions Example Licence Copyright © 2007-2014 PHD Computer Consultants Ltd, PHDCC

phdcc.CodeModule Overview

phdcc.CodeModule provides a simple way to add your own program code (and custom HTML) to a DNN site without having to write a full module or resort to using an IFRAME. Write your own ASP.NET/DNN code and HTML in a simple ascx user control - have it displayed by phdcc.CodeModule. Be careful who has access to this powerful functionality.

Write your own code in either Visual Basic (VB) or C-Sharp (C#). You can use a codebehind .vb or .cs file if you wish, but this is not required.

The Freeware version is called phdcc.CodeModuleFree and uses the DesktopModules\phdcc.CodeModuleFree\ directory.
The Retail version is called phdcc.CodeModule and uses the DesktopModules\phdcc.CodeModule\ directory.
The Freeware version always adds a "Powered by" message at the bottom of its output.

The retail version also works in a skin by replacing the [CODEMODULE] skin token.

BUG: the Settings button does not work if friendly URLs are turned off. Workaround: use the container menu instead.

Instructions

Download and install the module. Add the module to a page. You will then see this displayed:

When first loaded, go to Settings

Your next task is to write your code, eg based on the sample VB code below. Then upload it to the DesktopModules\phdcc.CodeModuleFree directory using FTP.

Next, click on Settings, or select Settings in the module container menu. Scroll down and expand "phdcc.CodeModule Settings". Enter the name of your control and press Update.

In Settings, specify the name of your control

Import and Export

phdcc.CodeModule can export and import the control filename - it *does not* export/import the control file contents. Access this functionality using the standard module menu Import Content and Export Content functions - or using [Host][Portals][Export Portal Template].

Retail skin token

The retail version of phdcc.CodeModule can also be used in a skin, ie to display your code/HTML at an appropriate point in your skin. An example of this is at the very bottom of this example page.

If you are using an HTML skin file, then add the [CODEMODULE] skin token to your skin. Then add a token setting to the associated skin.xml file: set the "ControlFile" setting to the name of your control file (which should be in the DesktopModules\phdcc.CodeModule\ directory). Then: either rebuild your skin package and upload, or re-parse the skin package if you have edited a live skin. Example token setting to add to skin.xml:

<Object>
<Token>[CODEMODULE]</Token>
  <Settings>
    <Setting>
      <Name>ControlFile</Name>
      <Value>viewSkin.ascx</Value>
    </Setting>
  </Settings>
</Object>

If you are working with an ASCX skin file, then add a suitable Register directive at the top, and add dnn:CODEMODULE at the desired point(s) in your skin.

<%@ Register TagPrefix="dnn" TagName="CODEMODULE" Src="~/DesktopModules/phdcc.CodeModule/View.ascx" %>
<dnn:CODEMODULE runat="server" id="dnnCODEMODULE" ControlFile="viewSkin.ascx" />

In the above examples, replace "viewSkin.ascx" with the name of your control file.

VB example

This is an example of possible VB code in view7.ascx - view in action. The example illustrates these points:

<%@ Control Language="VB" ClassName="view7" %>

<%@ Import Namespace="DotNetNuke.Entities.Users" %>

<script runat="server">

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  If Not IsPostBack Then
    lblGiven.Text = "unknown"
  End If
End Sub

Protected Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  If txtName.Text.Length > 0 Then
    lblGiven.Text = txtName.Text
  End If
End Sub

</script>

Hello <% =UserController.GetCurrentUserInfo.Username %>
<br />
Name: <asp:TextBox ID="txtName" runat="server" />
<asp:Button id="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" />
<br />
Your name is <asp:Label ID="lblGiven" runat="server" />

This produces this output (screenshot):

Example code module output

VB PortalModuleBase example

In your code it is often useful to have access to DNN properties. One of the most crucial is DotNetNuke.Entities.Modules.PortalModuleBase. Here's some VB code to get the PortalModuleBase for the phdcc.CodeModule control that holds your code:

<%@ Control Language="VB" ClassName="GetPortalModuleBase" %>

<%@ Import Namespace="DotNetNuke.Entities.Modules" %>
<%@ Import Namespace="DotNetNuke.Entities.Portals" %>

<script runat="server">

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim ViewControl As Control = Me.TemplateControl.Parent
  Dim View As Control = ViewControl.Parent
  If TypeOf (View) Is PortalModuleBase Then
    Dim pmb As PortalModuleBase = CType(View, PortalModuleBase)
    Dim ps As PortalSettings = pmb.PortalSettings
    lblInfo.Text = ps.HomeDirectory
  End If
End Sub
</script>

<asp:Label ID="lblInfo" runat="server" />

Version details

Retail version

01.02.036 February 2014Full namespace used for Implements
01.02.028 May 2011Supports UpdatePanel
01.02.0129 May 2009Support use in a skin using skin-token
01.01.0425 May 2009Cope if control name blank
01.01.0219 May 2009Commercial release

Freeware version

01.01.056 February 2014Full namespace used for Implements
01.01.048 May 2011Supports UpdatePanel
01.01.0325 May 2009Cope if control name blank
01.01.0119 May 2009Freeware release with DLL