Click here to Skip to main content
15,903,201 members
Articles / Web Development / HTML
Article

An ASP.NET Slide Show

Rate me:
Please Sign up or sign in to vote.
3.43/5 (30 votes)
30 Mar 2006CPOL1 min read 352.9K   14K   78   73
A simple slide show using AJAX in ASP.NET.

Introduction

I had been looking for the source of a web-based slide show for my own use. The features I wanted in my slide show pages were that it should dynamically select a picture in the server to display, it should display some transition effects, and it should not cause page refreshing. But I couldn’t find one of this kind. So I decided to code it myself.

There is a lot of source code to make the transition effect using JavaScript. But to address the dynamic selection of the picture to display and to avoid the page from refreshing, I used AJAX. There are a lot of AJAX frameworks and tools out there to choose from. But for this simple task, I just used the ASP.NET2’s built-in AJAX supported class System.Web.UI.ICallbackEventHandler.

The included source code will demonstrate the use of this class, and also how to use JavaScript to make the request to get the next image file and apply the transition effects. One thing I need to mention is when applying transition effects, the next image has to be completely loaded before playing the effect, otherwise, the picture display will not be smooth and will be flickering. I also address this in my JavaScript code.

In fact, this is a part of my photo album web project. For the live demo of the slide show in my photo album, click here.

Using the code

To use the source, unzip the project files to a folder, load the Slideshow.sln in Visual Studio 2005, and run it.

Hope my post is useful to you. Enjoy!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerRe: Doesn't work at all in Firefox Pin
Donald Shaw1-Jan-07 11:41
Donald Shaw1-Jan-07 11:41 
GeneralRe: Doesn't work at all in Firefox Pin
yannlh17-Jan-07 16:51
yannlh17-Jan-07 16:51 
GeneralRe: Doesn't work at all in Firefox Pin
alkm12023-Apr-07 3:00
alkm12023-Apr-07 3:00 
GeneralRe: Doesn't work at all in Firefox Pin
Azul SkyKnight6-Jun-07 6:33
Azul SkyKnight6-Jun-07 6:33 
GeneralRe: Doesn't work at all in Firefox Pin
Doan Quynh13-Nov-07 5:05
Doan Quynh13-Nov-07 5:05 
GeneralRe: Doesn't work at all in Firefox Pin
Azul SkyKnight16-Nov-07 4:34
Azul SkyKnight16-Nov-07 4:34 
Generalusing slideshow Pin
kurt11178023-May-06 3:24
kurt11178023-May-06 3:24 
GeneralRe: using slideshow Pin
Lang Deng23-May-06 8:45
Lang Deng23-May-06 8:45 
Thank you for your interest in my article. Actually the image files can be in anywhere under the root or a virtual directory of your web site, as long as they can be read by browsers, i.e. http://your_web_url/your_virtual_dir/your_image.jpg. What you need to do is to return these image URLs in the function GetNextImageUrl(). In my examples, it search files in the folder “images” under the directory of the application or the directory you deploy your web page.

string[] files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "images", "*.jpg");

Then it makes up the URL for one of these files randomly.

files[n].Replace(AppDomain.CurrentDomain.BaseDirectory, string.Empty

The returned string of the function GetNextImageUrl() will look like “images\your_image.jpg”. This is a relative path to your virtual directory of your Slideshow page. You don’t need to put any strings, such as http:// in front of it, since the client’s browsers will automatically make up the absolute URL to load your image, i.e. http://your_web_site/your_slideshow_directory/images/your_image.jpg. Of course you can return an absolute URL in GetNextImageUrl(). So the image file can be anywhere in your web site. A relative path can be only under your application (or Slideshow) virtual directory.

One thing you need to know is running a website project in VS2005 is a bit different from the deployment. In a project, it always uses the root directory with a port other than 80. In the web site deployment, you need to create a web folder or virtual directory, i.e. “Slideshow”. Then you can just copy your project into that folder. So users can access to your web with the URL as http://your_web_site/Slideshow/default.aspx.

Hope these help you understand my example.

GeneralRe: using slideshow Pin
AntonioN20-Jul-06 1:48
AntonioN20-Jul-06 1:48 
GeneralRe: using slideshow Pin
Dan Satria24-Jul-06 10:24
Dan Satria24-Jul-06 10:24 
GeneralRe: using slideshow Pin
ASPX_noob10-Oct-06 16:08
ASPX_noob10-Oct-06 16:08 
GeneralRe: using slideshow Pin
Lang Deng10-Oct-06 19:02
Lang Deng10-Oct-06 19:02 
GeneralRe: using slideshow Pin
ASPX_noob10-Oct-06 20:07
ASPX_noob10-Oct-06 20:07 
GeneralRe: using slideshow Pin
Lang Deng10-Oct-06 21:28
Lang Deng10-Oct-06 21:28 
GeneralRe: using slideshow Pin
ASPX_noob11-Oct-06 0:39
ASPX_noob11-Oct-06 0:39 
GeneralRe: using slideshow Pin
Lang Deng11-Oct-06 8:39
Lang Deng11-Oct-06 8:39 
QuestionRe: using slideshow [modified] Pin
ASPX_noob11-Oct-06 15:33
ASPX_noob11-Oct-06 15:33 
AnswerRe: using slideshow Pin
Lang Deng11-Oct-06 18:40
Lang Deng11-Oct-06 18:40 
GeneralRe: using slideshow Pin
ASPX_noob11-Oct-06 19:00
ASPX_noob11-Oct-06 19:00 
GeneralRe: using slideshow Pin
Lang Deng11-Oct-06 20:36
Lang Deng11-Oct-06 20:36 
GeneralRe: using slideshow Pin
ASPX_noob11-Oct-06 21:11
ASPX_noob11-Oct-06 21:11 
GeneralRe: using slideshow Pin
ASPX_noob12-Oct-06 21:28
ASPX_noob12-Oct-06 21:28 
GeneralRe: using slideshow Pin
yannlh17-Jan-07 16:47
yannlh17-Jan-07 16:47 
AnswerRe: using slideshow Pin
yannlh18-Jan-07 3:20
yannlh18-Jan-07 3:20 
AnswerRe: using slideshow Pin
yannlh18-Jan-07 4:02
yannlh18-Jan-07 4:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.