Home / AJAX

HOW TO Use the SlideShow Control

RSS
Modified on 2009/12/24 21:33 by Chris Muench Categorized as Uncategorized

SlideShow Demonstration

       

SlideShow Description

SlideShow is an extender that targets image controls. You can provide it with buttons to hit previous, next and play. You can configure the slideshow to play automatically on render, allow it loop through the images in a round robin fashion and also set the interval for slide transitions. You can use a page method to supply images to the slide show or use a webservice. In the sample above we have provided you with a slideshow that plays automatically on render and loops around to the first picture if you hit next on the last picture and vice versa if you hit previous on the first picture. The slideshow transitions pictures after 3 seconds.

Video - How Do I: Use the ASP.NET AJAX SlideShow Control?

SlideShow Client Code Sample

<%@ Page Language="C#" %>
<script runat="Server" type="text/C#">
    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static AjaxControlToolkit.Slide[] GetImages()
    {
        return new AjaxControlToolkit.Slide[] { 
        new AjaxControlToolkit.Slide("images/Blue hills.jpg", "Blue Hills", "Go Blue"),
        new AjaxControlToolkit.Slide("images/Sunset.jpg", "Sunset", "Setting sun"),
        new AjaxControlToolkit.Slide("images/Winter.jpg", "Winter", "Wintery..."),
        new AjaxControlToolkit.Slide("images/Water lilies.jpg", "Water lillies", "Lillies in the water"),
        new AjaxControlToolkit.Slide("images/VerticalPicture.jpg", "Sedona", "Portrait style picture")};
    }
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <style type="text/css"> </style> <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.js" type="text/javascript"></script> <script src="http://ajax.microsoft.com/ajax/beta/0911/Start.debug.js" type="text/javascript"></script> <script src="http://ajax.microsoft.com/ajax/beta/0911/extended/ExtendedControls.debug.js" type="text/javascript"></script> </head> <body> <form id="form1" runat="server"> <asp:AjaxScriptManager runat="server" EnablePartialRendering="false" EnablePageMethods="true" /> <script type="text/javascript"> Sys.require(Sys.components.slideShow, function() { $("#ss").slideShow({ slideShowServiceMethod: "GetImages", autoPlay: true, previousButtonID: "prev", nextButtonID: "next", playButtonID: "play", playButtonText: "Play", stopButtonText: "Stop", imageDescriptionLabelID: "desc", imageTitleLabelID: "title", loop: true, playInterval: 1000 }); }); </script> <div> <span id="title"></span> <img src="" id="ss" /> <span id="desc"></span> <div> <input type="button" id="prev" value="<<" /> &nbsp;&nbsp;&nbsp; <input type="button" id="play" value="play" /> &nbsp;&nbsp;&nbsp; <input type="button" id="next" value=">>" /> </div> </div> </form> </body> </html>

SlideShow Client Properties

SlideShow Server Code Sample

            <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="~/SlideShow/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="slideshowextend1" runat="server" 
                TargetControlID="Image1"
                SlideShowServiceMethod="GetSlides" 
                AutoPlay="true" 
                ImageTitleLabelID="imageTitle"
                ImageDescriptionLabelID="imageDescription"
                NextButtonID="nextButton" 
                PlayButtonText="Play" 
                StopButtonText="Stop"
                PreviousButtonID="prevButton" 
                PlayButtonID="playButton" 
                Loop="true" />

SlideShow Server Properties

The properties in italics are optional.

<ajaxToolkit:SlideShowExtender ID="SlideShowExtender1" runat="server" 
    TargetControlID="Image1" 
    SlideShowServiceMethod="GetSlides" 
    AutoPlay="true" 
    ImageTitleLabelID="imageTitle"
    ImageDescriptionLabelID="imageDescription"
    NextButtonID="nextButton" 
    PlayButtonText="Play" 
    StopButtonText="Stop" 
    PreviousButtonID="prevButton" 
    PlayButtonID="playButton" 
    Loop="true" />
  • SlideShowServicePath - Path to the webservice that the extender will pull the images from.
  • SlideShowServiceMethod - The webservice method that will be called to supply images. The signature of the method must match this:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public AjaxControlToolkit.Slide[] GetSlides() { ... }

Note that you can replace "GetSlides" with a name of your choice, but the return type and parameter name and type must exactly match, including case.
  • ContextKey - User/page specific context provided to an optional overload of the web method described by ServiceMethod/ServicePath. If the context key is used, it should have the same signature with an additional parameter named contextKey of type string:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public AjaxControlToolkit.Slide[] GetSlides(string contextKey) { ... }

Note that you can replace "GetSlides" with a name of your choice, but the return type and parameter name and type must exactly match, including case.
  • UseContextKey - Whether or not the ContextKey property should be used. This will be automatically enabled if the ContextKey property is ever set (on either the client or the server). If the context key is used, it should have the same signature with an additional parameter named contextKey of type string (as described above).
  • NextButtonID - ID of the button that will allow you to see the next picture.
  • PlayButtonID - ID of the button that will allow you to play/stop the slideshow.
  • PreviousButtonID - ID of the button that will allow you to see the previous picture.
  • PlayButtonText - The text to be shown in the play button to play the slideshow.
  • StopButtonText - The text to be shown in the play button to stop the slideshow.
  • PlayInterval - Interval in milliseconds between slide transitions in play mode.
  • ImageTitleLabelID - ID of Label displaying current picture's title.
  • ImageDescriptionLabelID - ID of Label describing current picture.
  • Loop - Setting this to true will allow you to view images in a round-robin fashion.
  • AutoPlay - Setting this to true will play the slideshow automatically on render.



SlideShow Additional Code Samples