phdcc.CodeModule DNN module
  search
Powered by FindinSite-MS
Write your own VB or C# code

Download, v01.00.02, 16 January 2008. Includes the VB source. Freeware. DotNetNuke 4 private assembly (PA) zip file. Please acknowledge PHDCC.
Forum Copyright © 2007-2008 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.

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.CodeModule directory using FTP or [Admin][File Manager].

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

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="TextBox1" runat="server" />
<asp:Button id="Button1" runat="server" Text="Go" OnClick="btnGo_Click" />
<br />
Your name is <asp:Label ID="Label1" 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" />