Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

ImageRotator

4.38/5 (11 votes)
26 Mar 20072 min read 1   1.3K  
An ImageRotator webcontrol that cylcles through images in a specific folder.

Screenshot - rotator.jpg

Introduction

I have always been interested in Web controls, but never had a chance to use one. So here is my very first one. This control shows images in a slide show manner. As soon as the page is finished loading, the slideshow starts. There are three buttons on the top of the image. Here, the slideshow can be stopped and started. It is also possible to use the Previous and Back buttons to cycle through the images manually.

Using the control

Just drop the control on an ASPX page. You will need to add an image folder to your project and fill this folder with the images you would like to display in the control. Next, tell the control where to look for the images. Write the virtual path to the property imageFolder. All the additional properties are described in detail below.

That is it. Start the application and watch the image rotator do it work.

Properties

  • imageFolder: Tells the control where to load the images from. The control will attempt to show all files in this folder. For this reason, you should only add files that can be shown in an 'img src' tag to this folder.
  • timerinterval: Sets the interval between the images in the slideshow. Values are in milliseconds. Default is 1000.
  • imageWidth: Specifies the image width in pixels. If this value is blank, the width of the image is used.
  • imageHeight: Specifies the image height in pixels. If this value is blank, the height of the image is used.
  • toggleStartText: The text to be displayed for the Start button. Default is Start.
  • toggleStopText: The text to be displayed for the Stop button. Default is Stop.
  • nextText: The text to be displayed for the Next button. Default is Next.
  • previousText: The text to be displayed for the Previous button. Default is Previous.
  • buttonStyle: The style to be applied to all three buttons.
  • startImage: The image to be displayed first when the slideshow starts.

Conclusion

Since this is the first web control I authored, I started with a clean slate. I started by writing the functionality I wanted in HTML and JavaScript. I figured at the end of the day a web control does nothing else than write HTML and JavaScript to the browser. If you look at the source code, you will find Regions labeled Original Function. In these regions is the original HTML/JavaScript I wrote. I thought about the functionality I wanted to expose, and wrote the properties respectively. At this point, all I needed to do was write the original code in the method RenderContents and insert the values of the properties where appropriate. I split the JavaScript methods and control elements to separate methods to make the code more legible.

Hope this code helped you to find a solution to a problem.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here