PART 6
Creating the View Control
Now we have a functioning edit control which allows us to add and delete images to the image list from which we will pick the image to display, let’s now turn our attention to the view control which is responsible for display the image.
Open BTBRandomImage.ascx drop an Image control on to the page and name it imgRandom
Next switch to the code behind file, first I’m going to clean a little bit of this up, remove the ISearchable from the list of base classes.
Remove the ISearchable stub from the optional interface region as well, these lines below should be deleted
public DotNetNuke.Services.Search.SearchItemInfoCollection
GetSearchItems(ModuleInfo ModInfo)
{
// included as a stub only so that the core knows this module
//Implements Entities.Modules.ISearchable
return null;
}
The last thing to-do on this class is to change the Page_Load method to display a random image. Here is the code I’m going to use to do this.
private void Page_Load(object sender, System.EventArgs e)
{
try
{
BTBRandomImageController objBTBRandomImage = new BTBRandomImageController();
ArrayList listImage;
int upperLimit;
if (!Page.IsPostBack)
{
listImage = objBTBRandomImage.GetByModules(ModuleId);
if(listImage.Count == 0)
{
//no images loaded hide the image control
//we're done here
imgRandom.Visible = false;
return;
}
//pick a random image from the arraylist and display it
upperLimit = listImage.Count;
Random rand = new Random((int)DateTime.UtcNow.Ticks);
BTBRandomImageInfo objImage = (BTBRandomImageInfo)
listImage[rand.Next(upperLimit)];
imgRandom.Visible = true;
imgRandom.AlternateText = objImage.imageAlt;
imgRandom.ImageUrl = PortalSettings.HomeDirectory + objImage.imageSrc;
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
Just compile the solution and test it out in your DotNetNuke portal, you should see that it all working fine.
If you do have a problem you can always debug the module by following these steps.
- Open the project property window and make sure you have the following settings for the Debugging option as shown below. The Start URL should be the URL to your own DotNetNuke portal.
- Make sure that your web.config for your DotNetNuke install has this setting <compilation debug="true" />
- Then you should be able to start the debugger in Visual Studio by hitting F5.

<< Previous Page Next Page >>