jquery Image Rotator for ASP.NET

22. October 2009

I wanted a simple simple image rotator and came across this one using jquery.  (Please check out my updated post, Part II, that allows being able to have a number navigation for the images as well). However, because I'm not a fan of static code, I wanted to make it work server side, but this was a great example on how to get started for the static code

http://www.alohatechsupport.net/webdesignmaui/maui-web-site-design/easy_jquery_auto_image_rotator.html

I basically modified the code from the post above and made the image part of it server side.  I left the CSS and Javascript code in place.  Well I switched the rotation from 6 seconds to 4 seconds.

So here is the concept of this code:

  • Have a server side ascx control
  • Assign the property for the path where the images are stored
  • Assign the property for the image file names delimited by a pipe (i.e, image1.jpg|image2.jpg)
  • Assign the property of the Width of the images
  • Assign the property of the Height of the images
  • Assign the property of the Alt Text for the images (all images share this)


As usual I will pretty much do a copy of paste of the code to make this happen. Comments are in the code as needed


NOTE: The path for my images in my test website was /images/

##########################################
Markup of the ImageRotator.ascx control
##########################################




]]>
]]>

##########################################
Codebehind of the ImageRotator.ascx control
##########################################




##########################################
Implementing the control on an aspx page
##########################################





And that is that. As you can see, I pretty much just take the property values needed and write out the HTML needed that the javascript will use.

If you needed to, in the Page Init or before the if statement in Page Load, you could grab the image names from any source and make then a pipe delimited string.  The source could be an XML file or a database, or whatever else you wanted to store the image names.

Well hopefully this helps other out there.  This makes a simple way to have a server side ASCX control that is a jquery image rotator for ASP.NET.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

ASP.NET, Javascript

Comments

pallavi
10/22/2009 8:14:40 PM #
Thanks for the solution, I have 6 images and i am displaying thumbnails below the image rotator,  if a user clicks on a thumbnail, the image rotation needs to start the rotation from an image which corrosponds to the thumbnail image.
Any idea how to achive this?
10/22/2009 9:41:10 PM #
hey pallavi, one solution would be when a user clicks on the thumbnail to add the css class "show" to that list item element it's intended for that's holding the image.  You'll notice in the rotate function in the javascript that's what it does to hide/show the image. It keeps swapping the "show" class. Let me know how it goes.

John M
praveen
2/5/2010 11:15:25 AM #
i want to show the next and previous image along with the auto scroll effect. I am able to show the next image by simply calling the rotate js function. But how can i show the previous image.

Please Help!!
2/5/2010 4:05:15 PM #
@praveen

I am working on providing a solution of what you are describing. As of right now I don't have much info for you. The one thing you could try is maybe in the rotate function where it hides the current image is when it removes the class show, add another class called previous or something like that. This way you know what image was before the one that just showed. Just a thought.  Sorry I don't much more for you right now. I will post a solution once I have it all done.  It may not be for a couple weeks though.
2/16/2010 8:09:56 AM #
Just wanted to give you a shout from the valley of the sun, great information. Much appreciated

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading