I tried working with context key for slideshowextender and got positive results. Most of the posts on web for this topic put emphasis on using inline webservice. But my code works with webservice added as an item of project.
Important points for proper functioning of code:
- Use “contextKey” property of slideshowextender for making call to parameterized method of webservice. Set UseContextKey="true" in slideshowextender. Also assign initial value for webmethod parameter in ContextKey e.g. ContextKey="Images". Later on you can pass parameter value in code behind(.aspx) depending on special conditions.
- Word “contextKey” in signature of webservice method is case sensitive.
“Public Function GetPhotos(ByVal contextKey As String)”
Mind it, minor change in case change can give you an error on webpage. So make sure that all letters except “K” in contextKey should be in lower case.
**Code for.asmx file(webservice)
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class slideservice
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetPhotos(ByVal contextKey As String) As AjaxControlToolkit.Slide()
Dim dir1 As New IO.DirectoryInfo(contextKey)
Dim ofiles = From file In dir1.GetFiles("*.jpg") Order By file.Name Select file
Dim ojaxslide(ofiles.Count - 1) As AjaxControlToolkit.Slide
If ofiles.Count = 0 Then Exit Function
Dim i As Integer
i = 0
For Each file In ofiles
ojaxslide(i) = New AjaxControlToolkit.Slide(IO.Path.GetFileName(contextKey) & "/" & file.Name, file.Name, IO.Path.GetFileNameWithoutExtension(file.Name))
i += 1
Next
Return ojaxslide
End Function
End Class
***code Behind
Partial Public Class photos
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Select Case Request.QueryString.Get("path")
Case "Temple"
SlideShowExtender1.ContextKey = Server.MapPath("Images")
Case "History"
SlideShowExtender1.ContextKey = Server.MapPath("Temple History")
End Select
End Sub
End Class
****Code for .aspx
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Login.Master" CodeBehind="photos.aspx.vb" Inherits="SelfPractice_project.photos" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div style="text-align:center">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Image ID="Image1" runat="server" BorderColor="Black" BorderStyle="Solid"
BorderWidth="2px" ImageUrl="~/Icon/HomePage.jpg" Height="300px" />
<br/>
<asp:Label ID="imageLabel1" runat="server" Font-Bold="True"
ForeColor="Black" Font-Size="Medium" ></asp:Label>
<h1 />
<asp:ImageButton ID="Prev" runat="server"
ImageUrl="~/Icon/Button Previous.Jpg" />
<asp:ImageButton ID="Play" runat="server" ImageUrl="~/Icon/Button Pause.Jpg" />
<asp:ImageButton ID="Next" runat="server"
ImageUrl="~/Icon/Button Next.Jpg" />
<cc1:SlideShowExtender ID="SlideShowExtender1" runat="server"
TargetControlID="Image1"
SlideShowServicePath="slideservice.asmx"
SlideShowServiceMethod="GetPhotos"
ContextKey="Images"
UseContextKey="true"
AutoPlay="true"
NextButtonID="Next"
PlayButtonText=""
StopButtonText=""
PreviousButtonID="Prev"
PlayButtonID="Play" Loop="true"
ImageDescriptionLabelID="imageLabel1"/>
</div>
</asp:Content>