ASP.NET SlideShowExtender从Web服务检索图像,但在执行时不执行任何操作

时间:2012-04-03 22:45:55

标签: c# asp.net sql-server ajax database

因此,在我的ASP.NET解决方案的默认页面上,我有一个SlideShowExtender对象,链接到一个从MSSQL数据库中检索幻灯片的WebMethod。通过调试,我可以确认从所述数据库成功创建了Slide对象,但是一旦页面加载,SlideShow元素就什么都不做。

以下是我的代码;我提前收到任何回复。谢谢。

编辑:我忘了提到我已经验证了图片网址的完整性;他们是对的。

Default.aspx(Default.aspx.cs只是一个带有空的Page_Load方法的标准代码隐藏):

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="Dissertation._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ToolkitScriptManager ID="scrptman" runat="server"></asp:ToolkitScriptManager>
        <asp:Image ID="imgBanner" Width="800" Height="300" runat="server"/>
        <br />
        <asp:Label ID="lblDesc" runat="server"></asp:Label>
        <asp:SlideShowExtender ID="sldShow" runat="server"   
        TargetControlID="imgBanner" 
        SlideShowServicePath="~/BannerImages.asmx"
        SlideShowServiceMethod="GetPhotos"   
        AutoPlay="true"    
        ImageDescriptionLabelID="lblDesc" 
        Loop="true" />
</asp:Content>

BannerImages.asmx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
using AjaxControlToolkit;

namespace Dissertation
{
/// <summary>
/// Summary description for BannerImages
/// </summary>
/// 
[System.Web.Script.Services.ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class BannerImages : System.Web.Services.WebService
{

    [WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public Slide[] GetPhotos()
    {
        List<Slide> images = new List<Slide>();
        ConnectionStringSettings settings = System.Configuration.ConfigurationManager.ConnectionStrings["Database"];
        SqlConnection conn = new SqlConnection(settings.ConnectionString);
        SqlCommand cmd = new SqlCommand("Select * from sol_bannerData", conn);
        SqlDataReader read = null;
        try
        {
            conn.Open();
            read = cmd.ExecuteReader();

            while(read.Read())
            {
                images.Add(new Slide(Server.MapPath("~/cms/uploads/banners/" + read["ImageURL"].ToString()), "", read["Description"].ToString()));
            }
        }
        catch(SqlException err)
        {
            images.Clear();
            images.Add(new Slide("", "", "Images could not be loaded: " + err.Message));
            return images.ToArray();
        }
        finally
        {
            if(read != null) read.Close();
            if(conn != null) conn.Close();
        }
        Slide[] toReturn = images.ToArray();
        return toReturn;




    }
}
}

1 个答案:

答案 0 :(得分:1)

问题解决了;我改用了jquery.cycle.all。