Click here to Skip to main content
15,314,060 members
Articles / Web Development / HTML
Posted 5 Sep 2007


27 bookmarked

Dynamic Slideshow of images using Ajax Toolkit

Rate me:
Please Sign up or sign in to vote.
2.17/5 (3 votes)
5 Sep 2007
This article shows how to display images in the form of slideshow dynamically


Recently, i have been trying out various things in Ajax Toolkit. I tried out the Slideshow concept and it worked out fine, but that code needs the image paths to be hard coded, so i thought what if i want to dislpay all the files in a particular folder dynamically? I worked on that and got it. I am presenting it here so that it may be useful for someone.


To work with this code you should have Ajax Toolkit installed. This example uses Ajax Toolkit

Using the code

//With in the form beginning & closing tags place the following code

<pre><div> <script runat="server" type="text/VB"> 
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetSlides() As AjaxControlToolkit.Slide()Dim ObjUIPage As New
Dim i As Integer = 0
Dim j As Integer 

<pre>//The below line specifies the Directory to be used.Here the images are in images folder of my application 

<pre>Dim DirInfo As New System.IO.DirectoryInfo(ObjUIPage.Server.MapPath("") & "\images")
Dim subDirs As System.IO.DirectoryInfo() = DirInfo.GetDirectories()

<pre>//The below line gets the list of files in the directory specified above 

<pre>Dim Files As System.IO.FileInfo() = DirInfo.GetFiles()

<pre>//The below line gives the file count, which is useful to specify the size of array 

<pre />

<pre>j = Files.Length
Dim mySlides() As Slide = New AjaxControlToolkit.Slide(j) {}
Dim di As System.IO.FileInfo

<pre />

<pre>//This loop continues upto the last file in the directory 

<pre />

<pre>For Each di In Files
mySlides(i) = New AjaxControlToolkit.Slide(di.FullName, di.Name, di.Name.Substring(0,(
di.Name.IndexOf(".")))Next diReturn mySlides 
i = i + 1
Next di

<pre>//this line sends the dynamically added details as AjaxControlToolkit.Slide 

<pre>End Function 

<pre><asp:ScriptManager runat="server" ID="SideShow" ></asp:ScriptManager>
<asp:Label runat="Server" ID="imageTitle" CssClass="slideTitle"/><br />
 <asp:Image ID="Image1" runat="server" Height="300" Style="border: 1px 
solid black;width:auto" ImageUrl="images/Blue hills.jpg" 
AlternateText="Blue Hills image" />
 <asp:Label runat="server" ID="imageDescription" CssClass="slideDescription">
</asp:Label><br /><br /> 
<asp:Button runat="Server" ID="prevButton" Text="Prev" Font-Size="Larger" />
 <asp:Button runat="Server" ID="playButton" Text="Play" Font-Size="Larger" />
 <asp:Button runat="Server" ID="nextButton" Text="Next" Font-Size="Larger" />
 <ajaxToolkit:SlideShowExtender ID="SlideShowExtender1" runat="server"
 TargetControlID="Image1" AutoPlay="true" ImageTitleLabelID="imageTitle" 
SlideShowServiceMethod = "GetSlides" 
ImageDescriptionLabelID="imageDescription" NextButtonID="nextButton" 
PlayButtonText="Play" StopButtonText="Stop" PreviousButtonID="prevButton"
 PlayButtonID="playButton" Loop="true" /> </div> 


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


About the Author

ravikiran valluri
Web Developer
India India
No Biography provided

Comments and Discussions

Questioni used the code after converted it to c# and still doesn't work ? Pin
Mohammad A. Amer5-May-13 14:54
professionalMohammad A. Amer5-May-13 14:54 

<script runat="Server" type="text/C#">
public static AjaxControlToolkit.Slide[] GetSlides()
System.Web.UI.Page ObjUIPage = new System.Web.UI.Page();
int i = 0;
int j = 0;
//'The below line specifies the Directory to be used.Here the images are in images folder of my application
System.IO.DirectoryInfo DirInfo = new System.IO.DirectoryInfo(ObjUIPage.Server.MapPath("") + "\\Storage\\Banner");
System.IO.DirectoryInfo[] subDirs = DirInfo.GetDirectories();
//'The below line gets the list of files in the directory specified above
System.IO.FileInfo[] Files = DirInfo.GetFiles();
//The below line gives the file count, which is useful to specify the size of array
j = Files.Length;
Slide[] mySlides = new AjaxControlToolkit.Slide[j + 1];
System.IO.FileInfo di = null;
//' This loop continues upto the last file in the directory
foreach (System.IO.FileInfo di_loopVariable in Files)
di = di_loopVariable;
// mySlides[i] = new AjaxControlToolkit.Slide(di.FullName, di.Name, di.Name.Substring(0, di.Name.IndexOf(".")));
mySlides[i] = mySlides[i] = new AjaxControlToolkit.Slide("\\Storage\\Banner\\"+di.Name, di.Name, di.Name.Substring(0, di.Name.IndexOf(".")));
i = i + 1;
return mySlides;
//' this line sends the dynamically added details as AjaxControlToolkit.Slide

<asp:scriptmanager runat="server" id="SideShow">

<asp:datagrid id="dgdarray" runat="server">

<asp:label runat="Server" id="imageTitle" cssclass="slideTitle">

<asp:image id="Image1" runat="server" height="300" style="border: 0px solid black;
width: auto" imageurl="/Storage/Banner/bannerImage1.jpg" alternatetext="Blue Hills image">
<asp:label runat="server" id="imageDescription" cssclass="slideDescription" text="Slide Show Desc.">

<asp:button runat="Server" id="prevButton" text="Prev" font-size="Larger">
<asp:button runat="Server" id="playButton" text="Play" font-size="Larger">
<asp:button runat="Server" id="nextButton" text="Next" font-size="Larger">
<ajaxtoolkit:slideshowextender id="SlideShowExtender1" runat="server" targetcontrolid="Image1"
="" autoplay="true" imagetitlelabelid="imageTitle" slideshowservicemethod="GetSlides" imagedescriptionlabelid="imageDescription" nextbuttonid="nextButton" playbuttontext="Play" stopbuttontext="Stop" previousbuttonid="prevButton" playbuttonid="playButton" loop="true">

QuestionIf it't not working try this Pin
Member 868581830-Mar-12 10:44
MemberMember 868581830-Mar-12 10:44 
GeneralMy vote of 2 Pin
Chesty17751-Jan-09 9:43
MemberChesty17751-Jan-09 9:43 
GeneralNot Working Pin
Paul Chu27-Sep-07 16:26
MemberPaul Chu27-Sep-07 16:26 
GeneralRe: Not Working Pin
ravikiran valluri28-Sep-07 1:50
Memberravikiran valluri28-Sep-07 1:50 
QuestionRe: Not Working Pin
CRizzle18714-Oct-07 17:46
MemberCRizzle18714-Oct-07 17:46 
AnswerRe: Not Working Pin
RoelAlblas6-Nov-07 7:04
MemberRoelAlblas6-Nov-07 7:04 
GeneralRe: Not Working Pin
Steve Loos27-May-08 16:17
MemberSteve Loos27-May-08 16:17 
AnswerRe: Not Working Pin
Pinging13-Jan-09 23:03
MemberPinging13-Jan-09 23:03 

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.