aDEFWEBSERVER
Los Angeles, CA *  Webmaster@ADefWebserver.com

Creating a Super-Simple DotNetNuke® Module
For absolute beginners! (For DotNetNuke Version 4.3.1) - Page 2 (Page 1)

Setting Up The Module

We will create the module using the following steps:

 

Create The Directories

Open your DotNetNuke website in Visual Studio.

   

Create the View Control

Right-click on the "DesktopModules" folder and select "New Folder"

Name the folder "SuperSimple"
Next, right-click on the "SuperSimple" folder and select "Add New Item..."
   
In the "Add New Item" box that opens:
  • Click on "Web User Control" under "Visual Studio Installed Templates".
  • Enter "SuperSimple.ascx" in the "Name" box.
  • Make sure the "Place code in a separate file" box is checked.
  • Click the "Add" button.
The "SuperSimple.ascx" file will be created in the "SuperSimple" folder under the "DesktopModules" folder.
Clicking the "plus" icon next to the file will display the associated code behind file "SuperSimple.ascx.vb" (or "SuperSimple.ascx.cs").
Double-click on the "SuperSimple.ascx" file and it will open up in the main editing window. Right now the page will be blank.

Click the "Source" button at the bottom of the page to switch to source view.

Enter the following code:

VB:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="SuperSimple.ascx.vb"
Inherits="DesktopModules_SuperSimple_SuperSimple" %>
Search:&nbsp;
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>&nbsp;
<asp:Button ID="btnSearch" runat="server" Text="Button" /><br />
<br /> 
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>

C#:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SuperSimple.ascx.cs"
 Inherits="DesktopModules_SuperSimple_SuperSimple" %>
Search:&nbsp;
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>&nbsp;
<asp:Button ID="btnSearch" runat="server" Text="Button" OnClick="btnSearch_Click" /><br />
<br /> 
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>

Click the "Design" button at the bottom of the page to switch to the design view.
Double-click on  "SuperSimple.ascx.vb" (or "SuperSimple.ascx.cs")
Replace all the code with the following code:
VB:
Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.Security.PortalSecurity
Partial Class DesktopModules_SuperSimple_SuperSimple
Inherits Entities.Modules.PortalModuleBase
Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
  ShowData("")
End If
 
End Sub
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
ShowData(txtSearch.Text)
End Sub
Private Sub ShowData(ByVal SearchString As String)
Dim mySqlString As New StringBuilder()
mySqlString.Append("SELECT FriendlyName, Description ")
mySqlString.Append("FROM {databaseOwner}{objectQualifier}DesktopModules ")
mySqlString.Append("WHERE Description like '%' + @SearchString + '%' ")
mySqlString.Append("ORDER BY FriendlyName")
Dim myParam As SqlParameter = New SqlParameter("@SearchString", SqlDbType.VarChar, 150)
myParam.Value = SearchString
Me.GridView1.DataSource = CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), myParam), IDataReader)
Me.GridView1.DataBind()
End Sub
End Class

C#:

using DotNetNuke;
using System.Web.UI;
using System.Text;
using System.Collections.Generic;
using System.Reflection;
using DotNetNuke.Security;
using System.Data.SqlClient;
using System.Data;
using DotNetNuke.Data;
 
partial class DesktopModules_SuperSimple_SuperSimple : DotNetNuke.Entities.Modules.PortalModuleBase 
{    
    protected void Page_Load(object sender, System.EventArgs e) {
        if (!Page.IsPostBack) 
        {
            ShowData("");
        }
    }
    
    protected void btnSearch_Click(object sender, System.EventArgs e) {
        ShowData(txtSearch.Text);
    }
    
    private void ShowData(string SearchString) {
        StringBuilder mySqlString = new StringBuilder();
        mySqlString.Append("SELECT FriendlyName, Description ");
        mySqlString.Append("FROM {databaseOwner}{objectQualifier}DesktopModules ");
        mySqlString.Append("WHERE Description like \'%\' + @SearchString + \'%\' ");
        mySqlString.Append("ORDER BY FriendlyName");
        SqlParameter myParam = new SqlParameter("@SearchString", SqlDbType.VarChar, 150);
        myParam.Value = SearchString;
        this.GridView1.DataSource = ((IDataReader)(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), myParam)));
        this.GridView1.DataBind();
    }
 
}
Select BUILD from the menu bar and select "Build Page".
The page should build without errors.
   
   

The step that remains:

   

BACK
 

Next: Register the module in DotNetNuke

 

   
   
 

DotNetNuke MarketPlace

(C) by Michael Washington - ADefWebserver.com - Webmaster@ADefWebserver.com

DotNetNuke® is a registered trademark of Perpetual Motion Interactive Systems Inc.