我正在尝试基于c-sharpcorner.com上提供的演示代码来实现'ajaxToolkit:SlideShowExtender'属性。 https://www.c-sharpcorner.com/uploadfile/prathore/ajax-slideshowextender-control/
从我的.aspx文件中:
<%@ Page Title="Producten" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Producten.aspx.cs" Inherits="Producten" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit"%>
<asp:Content ID="ContentStyle" ContentPlaceHolderID="Stylesheets" Runat="Server">
<link rel="stylesheet" href="/Content/Site.css" type="text/css" />
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<table style="align-content:center; width:500px; height:250px;">
<tr style="align-content:center;">
<td>
<asp:Label ID="lableImageDetail" runat="server" ForeColor="#000000" />
</td>
</tr>
<tr style="align-content:center;">
<td>
<asp:Image runat="server" ID="image1" Height="250" Width="400" />
</td>
</tr>
<tr style="text-align:center;">
<td>
<asp:Button ID="buttonPrev" runat="Server" Text="Previous" Width="80px" />
<asp:Button ID="buttonPlay" runat="server" Text="Play" Width="80px" />
<asp:Button ID="buttonNext" runat="Server" Text="Next" Width="80px" />
</td>
</tr>
</table>
<ajaxToolkit:SlideShowExtender ID="slideShowExtender1" runat="Server" TargetControlID="image1"
ImageDescriptionLabelID="lableImageDetail" Loop="true" AutoPlay="true" StopButtonText="Stop"
PlayButtonText="Play" NextButtonID="buttonNext" PreviousButtonID="buttonPrev"
PlayButtonID="buttonPlay" SlideShowServiceMethod="GetSlides" />
</asp:Content>
我后面的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using System.IO;
using System.Web.Services;
using System.Web.Script.Services;
public partial class Producten : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static AjaxControlToolkit.Slide[] GetSlides()
{
AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[5];
slides[0] = new AjaxControlToolkit.Slide("images-producten/image1.jpg", "First image of my album", "First Image");
slides[1] = new AjaxControlToolkit.Slide("images-producten/image2.tif", "Second image of my album", "Second Image");
slides[2] = new AjaxControlToolkit.Slide("images-producten/image3.tif", "Third image of my album", "Third Image");
slides[3] = new AjaxControlToolkit.Slide("images-producten/image4.jpg", "Fourth image of my album", "Fourth Image");
slides[4] = new AjaxControlToolkit.Slide("images-producten/image5.jpg", "Fifth image of my album", "Fifth Image");
return (slides);
}
}
PS。我正在运行Visual Studio 2017版本15.2(26430.16)和Microsoft .NET Framework版本4.7.03056。 (targetFramework .NET = 4.5.2)
我非常想看看网页上的滑块中显示的图像。 感谢所有帮助!
答案 0 :(得分:1)
您要查找的代码适用于Vs 2005和.net 2.0。 最新的工作代码在这里。 问:ScriptManager可能有某些缺失或错误,它是在“ Site.master”页面上配置的,由于它只能包含一个ScriptManager,所以无法将其添加到aspx页面。 **
A。您必须将项目升级到.net 4.0,然后更改web.config 也。
**
https://github.com/DevExpress/AjaxControlToolkit/tree/master/AjaxControlToolkit.SampleSite/SlideShow
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<section name="ajaxControlToolkit" type="AjaxControlToolkit.AjaxControlToolkitConfigSection, AjaxControlToolkit" requirePermission="false"/>
</configSections>
<ajaxControlToolkit useStaticResources="true" renderStyleLinks="false" htmlSanitizer="AjaxControlToolkit.HtmlEditor.Sanitizer.DefaultHtmlSanitizer, AjaxControlToolkit.HtmlEditor.Sanitizer" tempFolder="~/Temp"/>
<location path="Temp">
<system.webServer>
<handlers>
<clear/>
</handlers>
<modules>
<clear/>
</modules>
</system.webServer>
</location>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.7" />
</system.Web>
-->
<system.web>
<compilation debug="true" targetFramework="4.7"/>
<machineKey validation="SHA1" decryptionKey="7EE421F6987EAFF4998E0F2ED5544AF1B931C82A1602BC2E" validationKey="5278D83EDD8E36C27E019D3E975D62A3FDF0E8EF50DB69F659D03EB18A4459D2B3271AA075173012EF122E2B7BFA49CDE16CC0DCC68F3E862E1EEE491D300DC9"/>
<siteMap>
<providers>
<add name="SamplesSiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="~/Samples.sitemap"/>
</providers>
</siteMap>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<controls>
<add assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
<add namespace="InfoBlock" tagPrefix="samples"/>
</controls>
</pages>
<trust level="Medium"/>
</system.web>
<system.webServer>
<handlers>
<add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
</handlers>
</system.webServer>
<runtime>
</runtime>
</configuration>
答案 1 :(得分:1)
我今天看到了你的问题...
您已经在项目中添加了文件夹名称“图像” ...,并根据您的喜好添加了多个图像...。
在.aspx页面中添加ajax工具包参考。...
<%@注册程序集=“ AjaxControlToolkit”命名空间=“ AjaxControlToolkit” TagPrefix =“ cc1”%>
.aspx页面代码.....
<html>
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:Button ID="btnPrevious" runat="server" Text="<<" Font-Size="20" />
</td>
<td>
<asp:Image ID="Image1" runat="server" Height="300" Width="300" />
<cc1:SlideShowExtender ID="SlideShowExtender" runat="server" TargetControlID="Image1"
SlideShowServiceMethod="GetImages" ImageTitleLabelID="lblImageTitle" ImageDescriptionLabelID="lblImageDescription"
AutoPlay="true" Loop="true" PlayButtonID="btnPlay" StopButtonText="Stop"
PlayButtonText="Play" NextButtonID="btnNext" PreviousButtonID="btnPrevious">
</cc1:SlideShowExtender>
</td>
<td>
<asp:Button ID="btnNext" runat="server" Text=">>" Font-Size="20" />
</td>
</tr>
<tr>
<td colspan="3" align="center">
<asp:Button ID="btnPlay" runat="server" Text="Play" Font-Size="20" />
</td>
</tr>
<tr>
<td colspan="3" align="center">
<br />
<b>Name:</b>
<asp:Label ID="lblImageTitle" runat="server" Text="Label" /><br />
<b>Description:</b>
<asp:Label ID="lblImageDescription" runat="server" Text="Label" />
</td>
</tr>
</table>
</form>
</body>
.cs页面代码...
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 CS : System.Web.UI.Page
{
[WebMethod]
[ScriptMethod]
public static Slide[] GetImages()
{
List<Slide> slides = new List<Slide>();
string path = HttpContext.Current.Server.MapPath("~/images/");
if (path.EndsWith("\\"))
{
path = path.Remove(path.Length - 1);
}
Uri pathUri = new Uri(path, UriKind.Absolute);
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
Uri filePathUri = new Uri(file, UriKind.Absolute);
slides.Add(new Slide
{
Name = Path.GetFileNameWithoutExtension(file),
Description = Path.GetFileNameWithoutExtension(file) + " Description.",
ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString()
});
}
return slides.ToArray();
}
}
注意:-只需以适当的方式将此代码放入您的项目中即可...这将起作用...我已经在我的项目中使用了此代码。....我正在使用3.5版本。
。答案 2 :(得分:0)
您似乎缺少了处理“ ScriptResource.axd”请求的处理程序。
<system.webServer>
<handlers>
<add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" preCondition="integratedMode" />
</handlers>