DotNetNuke, ASP.NET, Web Development Blog

Tableless Banners in DotNetNuke

A quick conversion of the DNN Banners Module to Tableless Display

We've been working on our first site that really makes heavy use of DotNetNuke's Banners module for displaying revenue generating ads. Today I was trying to get the banners module to work for a Newsletter piece (more on that later) of the site that has a very tight layout but the way Banners is implemented didn't allow me to do what I needed. Currently, the banners module renders banners in a table and the only way to add spacing between banners is by setting cellpadding and/or cellspacing. We needed a solution where we could ad space between the banners without adding space on the sides of the banners. This wasn't possible with the current implemenation (other than by adding whitespace to the banner images which we didn't feel was a good solution) so we needed another solution.

I could have gone in and made a couple quick changes to the banners module to get it to do what I needed but then, we would've have had to reapply the changes every time we upgraded the site.

Instead, I spent about 10 minutes creating a new module based on the existing banners module. Luckily, DNN makes this easy.

The change to the code is the easy part (though really it was all very easy). I just changed the RepeatLayout attribute for the DataList to "Flow" instead of the default "Table" and then added a class to the label within which the banner is implemented.

The more involved process was copying and renaming the files and class. In all though, it took less then 10 minutes to think up and implement this solution.

The following steps assume you have a decent understanding of DNN's Module Definitions. This isn't really intended for novices as they generally won't understand the whole point of this.

The basic steps you need to take are:

  1. Find the code that drives Banners module. The code consists of only two files, banner.ascx and banner.ascx.vb in the Admin/Skins directory.
  2. Create a new directory under the DesktopModules directory called TablelessBanners and copy the two banner files into the new directory.
  3. Rename the files to TablelessBanner.ascx and TablelessBanner.ascx.vb
  4. Update the class name in both the ascx and ascx.vb files to TablelessBanner (instead of Banner). You could also just change the namespace instead. Just something to avoid duplicates.
  5. In the ascx file, add the following to the DataList definition, RepeatLayout="Flow". This will cause the DataList Control to render semantically rather than as a table.
  6. To the lblItem label, add, cssclass="tablelessBanner".
  7. Now, in one of your css files (usually the css for your skin), you'll need to define the styles for the tablelessBanner class.
  8. Now you just need to create the module definition for the module through the Host->Module Definitions page and add the new module to your page.
That's it. You should now be able to style your banners the way you want through your class. You can of course modify the code further to give greater flexibility in rendering and layout.
I'm hoping to develop this module further and then make it available as a free download and/or donate it to DotNetNuke corp for inclusion in the core.


Robert Mckimmey Says:
11/23/2014 5:44:44 AM
Dave, great article. I am in great need of taking your ideas and creating a 'responsive' banner module using BootStrap. Have you done anything else with your ideas on this since your original publication?? --Robert
Leave a Comment
Email: (not displayed)

Enter the code shown above:

Return to previous page