Monday, 17 November 2014

ASP.NET AJAXControlToolkit SlideShowExtender control without using Web Service example

Hi friends,in this article I will explain about ASP.NET AJAXControlToolkit SlideShowExtender control without using Web Service example.
SlideShowExtender used to how to build image Slide Show by fetching images from Folder or Directory using the ASP.Net AJAX Control Toolkit SlideShow Extender control.
Download and add AjaxControlToolkit in your website.

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

ASP.NET:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ASP.NET AJAXControlToolkit SlideShowExtender control without using Web Service
        example </title>
    <style type="text/css">
        .btn
        {
            width: 100px;
            background-color: Maroon;
            color: White;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <table border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                <asp:Image ID="SlideShowImage" runat="server" Width="250px" Height="250px" BorderColor="Black" />
                <Ajax:SlideShowExtender ID="SlideShowExtender" runat="server" TargetControlID="SlideShowImage"
                    SlideShowServiceMethod="GetImages" ImageTitleLabelID="lblImgTitle" ImageDescriptionLabelID="lblImgDescription"
                    AutoPlay="true" Loop="true" PlayButtonID="btnPlay" StopButtonText="Stop" PlayButtonText="Play"
                    NextButtonID="btnNext" PreviousButtonID="btnPrevious">
                </Ajax:SlideShowExtender>
            </td>
        </tr>
        <tr>
            <td style="height: 10px">
            </td>
        </tr>
        <tr>
            <td colspan="3" align="center">
                <asp:Button ID="btnPrevious" runat="server" Text="Previous" CssClass="btn" />
                <asp:Button ID="btnPlay" runat="server" Text="Play" CssClass="btn" />
                <asp:Button ID="btnNext" runat="server" Text="Next" CssClass="btn" />
            </td>
        </tr>
    </table>
    <table>
        <tr>
            <td style="height: 10px">
            </td>
        </tr>
        <tr>
            <td style="font-weight: bold">
                Image Title
            </td>
            <td>
                :
            </td>
            <td>
                <asp:Label ID="lblImgTitle" runat="server" Text="Label" />
            </td>
        </tr>
        <tr>
            <td style="font-weight: bold">
                Description
            </td>
            <td>
                :
            </td>
            <td>
                <asp:Label ID="lblImgDescription" runat="server" Text="Label" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

C#:
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using AjaxControlToolkit;
using System.Web.Services;
using System.Web.Script.Services;
using System.Collections.Generic;

public partial class SlideShow : System.Web.UI.Page
{
[WebMethod]
public static Slide[] GetImages()
{
    string[] imagenames = System.IO.Directory.GetFiles(HttpContext.Current.Server.MapPath("~/Images"));
    AjaxControlToolkit.Slide[] images = new AjaxControlToolkit.Slide[imagenames.Length];
    for (int i = 0; i < imagenames.Length; i++)
    {
        string[] file = imagenames[i].Split('\\');
        images[i] = new AjaxControlToolkit.Slide("Images/" + file[file.Length - 1], file[file.Length - 1], "");
    }
    return images;
    
}
}

VB.NET:
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO
Imports AjaxControlToolkit
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Collections.Generic

Partial Public Class SlideShowVB
    Inherits System.Web.UI.Page
    <WebMethod()> _
    Public Shared Function GetImages() As Slide()
        Dim imagenames As String() = System.IO.Directory.GetFiles(HttpContext.Current.Server.MapPath("~/Images"))
        Dim images As AjaxControlToolkit.Slide() = New AjaxControlToolkit.Slide(imagenames.Length - 1) {}
        For i As Integer = 0 To imagenames.Length - 1
            Dim file As String() = imagenames(i).Split("\"c)
            images(i) = New AjaxControlToolkit.Slide("Images/" + file(file.Length - 1), file(file.Length - 1), "")
        Next
        Return images

    End Function
End Class


The output of the above code as shown in the below figure.

No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.