Thursday, 22 November 2012

ASP.NET C#: How to make slideshow

SlideShow.aspx file:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SlideShow.aspx.cs" Inherits="ControlPages_SlideShow" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!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></title>
</head>
<body>   
   
    <form id="form1" runat="server">
     <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
     <div align="center" style="vertical-align:top">
        <table cellspacing="0px;">
        <tr>
            <td>
                <asp:Image ID="slideImage" runat="server"
                    ImageUrl="~/Images/MyPictures/masud_1.jpg"
                    AlternateText="Slide Show" CssClass="slideshow-img" />
            </td>
        </tr>
        <tr>
            <td style="background-color:Teal;">
                <asp:Label ID="imageLabel" runat="server"></asp:Label>
            </td>
        </tr>
       
        </table>
            <asp:SlideShowExtender ID="SlideShowExtender1" runat="server"
                AutoPlay="True"
                Loop="True"
                SlideShowServiceMethod="GetSlides"
                SlideShowServicePath="~/SlideService.asmx"
                TargetControlID="slideImage"
                ImageDescriptionLabelID="imageLabel">
            </asp:SlideShowExtender>
    </div>
    </form>
</body>
</html>


SlideService.cs file:
  • Right click on project root folder and select--> Add New Item--> select Web service. It will add two file with extension .asmx and .cs in the App_Code with the same name.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for SlideService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class SlideService : System.Web.Services.WebService {

    public SlideService ()
    {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    [WebMethod]
    public AjaxControlToolkit.Slide[] GetSlides()
    {
        AjaxControlToolkit.Slide[] myslide=new AjaxControlToolkit.Slide[5];

        myslide[0] = new AjaxControlToolkit.Slide("Images/MyPictures/masud_1.jpg", "masud 01", "Me at my premises");
        myslide[1] = new AjaxControlToolkit.Slide("Images/MyPictures/masud_2.jpg", "masud 02", "Me at party");
        myslide[2] = new AjaxControlToolkit.Slide("Images/MyPictures/masud_3.jpg", "masud 03", "Me at Canary Wharf: 1");
        myslide[3] = new AjaxControlToolkit.Slide("Images/MyPictures/masud_4.jpg", "masud 04", "Me at Canary Wharf: 2");
        myslide[4] = new AjaxControlToolkit.Slide("Images/MyPictures/masud_5.jpg", "masud 05", "Me at home");

        return myslide;

    }
}



No comments:

Post a Comment