PART 2
Defining The Module In DotNetNuke
The first thing to do is define the module in your DotNetNuke install, that way we can test the module. To add the module definition we are going to manually add it.
- Login to your DotNetNuke install with the host account
- Select the Module Definitions page from the Host menu
- Click the Add New Module Definition hyperlink
- Right now we need to complete the fields as below
- Module Name: BTBRandomImage
- Folder Name: BTBRandomImage
- Friendly Name: BTBRandomImage
- Description: Displays a random image
- Version: 1.0.0
- Controller Class: BiteTheBullet.DNN.Modules.BTBRandomImage.Business. BTBRandomImageController, BiteTheBullet.DNN.Modules.BTBRandomImage
- Then click update.
Most of the settings should be straight forward, the only one that needs explaining is controller class. This takes a type, assembly value which defines the controller class. We need to do since the controller class will implement the option interfaces for import/export.
Our Visual Studio 2003 wizard had created this type already for us so it was just a class of entering the type and assembly details.

Ok we’re nearly done, next type BTBRandomImage into the New Definition field then click Add Definition.
Right now we are going to define the user controls that our module will use. Since this is a really simple module we are only going to use two user controls, both of which are already created in our VS solution by the project template.
BTBRandomImage.ascx – this is the user control which will display the random image
BTBRandomImageEdit.ascx – this it the edit user control that will allow us to define what images to select the random image from.
So setting these two user controls up is done like this.
- Click Add Control hyperlink
- Select the BTBRandomImage.ascx object as the Source
- Set the type to View
- Click Update
- Then click Add Control hyperlink
- Set the Key: Edit
- Set the title to Edit Random Image
- Set the source to BTBRandomImageEdit.ascx
- Set the type to Edit
- Click Update


What did we just do? Well we defined which user controls to use for displaying the module and for editing the module.
An important point to note is that we need to have one user control that doesn’t have a key defined, this will become the default user control to use when the module is loaded on a page, hence the reason why BTBRandomImage.ascx doesn’t have a key assigned to it.
Database Objects
Ok to create the database table just we’re going to use Enterprise Manager. Create a new table in the database called BTBRandomImage with the following columns.
Note I’ve not got a naming prefix on my tables in my database, if you have then you should follow that to name your table i.e. if all the tables are called dnn_<table> then name this table similarly.
| Column Name |
Type |
Size |
Allow Nulls |
Notes |
| imageID |
Int |
4 |
No |
Set as primary key |
| moduleID |
Int |
4 |
No |
Foreign key to Modules table |
| imageSrc |
VarChar |
1000 |
No |
|
| imageAlt |
VarChar |
500 |
Yes |
|
You should have a table that looks like this.

Next we need to create the foreign key relation with the moduleID column, just right click on the table and select Relationships… then set it up as below.

That’s the database table complete, now we can use CodeSmith to generate the code and stored procedures for accessing the database.
I’ve created a SQL script that you can use to create the table if that’s what you prefer, just make sure that the table name is correct for your database, see the point above for more details.
<< Previous Page Next Page >>