使用AjaxToolKit的图像幻灯片放映 [英] Image Slide Show using AjaxToolKit

查看:48
本文介绍了使用AjaxToolKit的图像幻灯片放映的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们

我试图使用AjaxControlToolkit.Slide()和在线代码创建动态图像幻灯片,但是随后出现以下错误:
未知的Web方法GetSlides.
参数名称:methodName"


下面是代码:


Hi Guys

Am trying to create a dynamic Image Slide Show using AjaxControlToolkit.Slide() with code I got online,But then I get the error below:
"Unknown web method GetSlides.
Parameter name: methodName "


Below is the code:


<script runat="Server" type="text/C#">
        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
    public AjaxControlToolkit.Slide[] GetSlides()
    {
        string[] fileNames = System.IO.Directory.GetFiles(Server.MapPath("images"));
        AjaxControlToolkit.Slide[] images = new AjaxControlToolkit.Slide[fileNames.Length];
        for (int i = 0; i < fileNames.Length; i++)
        {
            string[] file = fileNames[i].Split('\\');
            images[i] = new AjaxControlToolkit.Slide("images/" + file[file.Length - 1], "", "");
        }
        return images;
       </script>

 <asp:Image ID="Image1" runat="server" 
                Height="300"
                Style="border: 1px solid black;width:200" 
              
                AlternateText="Blue Hills image" />
     <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" />


这一切都在客户端运行,为什么它找不到Web方法GetSlides?


This all runs in the client side, Why cant it find the web method GetSlides?

推荐答案

您是否编写了一个名为GetSlides的Web服务方法以供此代码调用?您没有说为什么期望它应该能够找到这种方法.您是否复制并粘贴了该代码,并假定无需编写该方法就可以使用该代码?
Have you written a webservice method called GetSlides for this code to call ? You don''t say why you expect it SHOULD be able to find this method. Did you copy and paste and assume this code would work without writing that method ?




几年前,我使用示例代码遇到了同样的问题.我在 http://www.asp.net/web-forms/videos/ajax-control-toolkit/how-do-i-use-the-aspnet-ajax-slideshow-extender [
我想通了,我们应该包括[System.Web.Script.Services.ScriptService],删除静态,一切都保持不变.这将解决错误未知的Web方法GetSlides ...",这是SlidesService.cs的示例:



I had the same problem using the sample code couple years ago. I posted a solution on http://www.asp.net/web-forms/videos/ajax-control-toolkit/how-do-i-use-the-aspnet-ajax-slideshow-extender[^] Hope it will works for you too.

"

i figured it out, we should include [System.Web.Script.Services.ScriptService], remove the static and everything remain the same. This will take care of the error "unknown web method GetSlides..." here is a sample for SlidesService.cs:

using System;

using System.Web;

using System.Collections;

using System.Web.Services;

using System.Web.Script.Services;

using System.Web.Services.Protocols;

using System.Configuration;

using System.Web.UI.WebControls;

using System.Web.UI;

/// <summary>

/// Summary description for SlidesService

/// </summary>

[WebService(Namespace = "<a rel="nofollow" target="_new" href="http://tempuri.org/"></a>)]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

public class SlidesService : System.Web.Services.WebService {

   public SlidesService () {

       //Uncomment the following line if using designed components

       //InitializeComponent();

   }

   [System.Web.Services.WebMethod]    

   public AjaxControlToolkit.Slide[] GetSlides()

   {

       System.Web.UI.WebControls.SqlDataSource ds = new SqlDataSource();

       ds.ConnectionString = ConfigurationManager.ConnectionStrings["pictureConnectionSt ring"].ConnectionString;

       string testConn = ConfigurationManager.ConnectionStrings["pictureConnectionSt ring"].ConnectionString;

       string mySelect;

       int count = 0;

       mySelect = "SELECT TOP 20 * FROM [pictureName] ORDER BY NEWID()";

       ds.SelectCommand = mySelect;

       System.Data.DataView dv = (System.Data.DataView)ds.Select(new DataSourceSelectArguments());

       count = dv.Table.Rows.Count;

       AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[count];

       try

       {

           for (int i = 0; i < count; i++)

           {

               slides[i] = new AjaxControlToolkit.Slide("images/" + dv.Table.Rows[i]["path"].ToString(),

                                                                    dv.Table.Rows[i]["name"].ToString(),

                                                                    dv.Table.Rows[i]["description"].ToString());

           }

       }

       catch { }

       //slides[0] = new AjaxControlToolkit.Slide("images/Blue hills.jpg", "Blue Hills", "Go Blue");

       //slides[1] = new AjaxControlToolkit.Slide("images/Sunset.jpg", "Sunset", "Setting sun");

       //slides[2] = new AjaxControlToolkit.Slide("images/Winter.jpg", "Winter", "Wintery...");

       //slides[3] = new AjaxControlToolkit.Slide("images/Water lilies.jpg", "Water lillies", "Lillies in the water");

       //slides[4] = new AjaxControlToolkit.Slide("images/VerticalPicture.jpg", "Sedona", "Portrait style picture");

       return (slides);

   }

}


"


这篇关于使用AjaxToolKit的图像幻灯片放映的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆