RSS feed icon BTB Shadow Man BiteTheBullet.co.uk logo

Page 1 2 3 4 5 6 7 8

DotNetNuke Random Image Tutorial - Part 2

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.

  1. Login to your DotNetNuke install with the host account
  2. Select the Module Definitions page from the Host menu
  3. Click the Add New Module Definition hyperlink
  4. 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
  1. 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.

Defining the module

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.

  1. Click Add Control hyperlink  
  2. Select the BTBRandomImage.ascx object as the Source
  3. Set the type to View
  4. Click Update
  5. Then click Add Control hyperlink
  6. Set the Key: Edit
  7. Set the title to Edit Random Image
  8. Set the source to BTBRandomImageEdit.ascx
  9. Set the type to Edit
  10. Click Update

Creating the user control

Creating the edit control

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.

Database table creation

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.

Foreign  key creation

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 >>

Privacy PolicyTerms and ConditionsCopyright © 2005 - 2008 BiteTheBullet.co.uk