在asp.net ajax 1.0中,有相当多的ajaxtoolkit好的控件,这里选一些十分精彩的来进行介绍
1)slideshow控件。这个控件十分好,可以开发一个简单的相册控件
首先,必须要有一个web服务
照片的提供通过后端Web Services来完成,可通过SlideShowServiceMethod 属性指定要提供照片的Web Method(或Page Method)名称,该Web Method声明的方式如下:
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetSlides() As AjaxControlToolkit.Slide()
Dim pic(2) As AjaxControlToolkit.Slide
'图象来源
pic(0) = New AjaxControlToolkit.Slide("照片位置URL", "照片名称", "照片说明")
pic(1) = New AjaxControlToolkit.Slide("...", "...", "...")
pic(2) = New AjaxControlToolkit.Slide("...", "...", "...")
...
Return pic
End Function
然后加一个图片按钮,再加几个如上一张,下一张等的按钮
<asp:Button ID="btn_Prev" runat="server" Text="上一张" /> <asp:Button ID="btn_play"
runat="server" Text="播放" />
<asp:Button ID="btn_next" runat="server" Text="下一张" /> 图片说明:<asp:Label ID="Label1"
runat="server" Text="Label"></asp:Label><br />
<asp:Image ID="Image1" runat="server" /><br />
<cc1:SlideShowExtender ID="SlideShowExtender1" runat="server" TargetControlID="Image1">
</cc1:SlideShowExtender>
web服务的设置
'提供图象来源的Web Services
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetSlides() As AjaxControlToolkit.Slide()
Dim pic(3) As AjaxControlToolkit.Slide
'图象来源
pic(0) = New AjaxControlToolkit.Slide("images/airplant.gif", "airplant.gif", "飞机")
pic(1) = New AjaxControlToolkit.Slide("images/spiderman3.jpg", "spiderman3.jpg", "蜘蛛人")
pic(2) = New AjaxControlToolkit.Slide("images/superMan.gif", "superMan.gif", "超人")
pic(3) = New AjaxControlToolkit.Slide("images/batman.jpg", "batman.jpg", "蝙蝠侠")
Return pic
End Function
后台逻辑编码
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'要附挂在哪一个控件上
Me.SlideShowExtender1.TargetControlID = Me.Image1.ID
'后端Web Method名称
Me.SlideShowExtender1.SlideShowServiceMethod = "GetSlides"
'自动播放
Me.SlideShowExtender1.AutoPlay = True
'自动重复
Me.SlideShowExtender1.Loop = True
'播放间隔(每张相片显示时间)
Me.SlideShowExtender1.PlayInterval = 3000
'下一张相片钮
Me.SlideShowExtender1.NextButtonID = Me.btn_next.ID
'上一张相片钮
Me.SlideShowExtender1.PreviousButtonID = Me.btn_Prev.ID
'播放/停止钮
Me.SlideShowExtender1.PlayButtonID = Me.btn_play.ID
'播放/停止钮在播放时显示的文字
Me.SlideShowExtender1.StopButtonText = "停止"
'播放/停止钮在停止时显示的文字
Me.SlideShowExtender1.PlayButtonText = "播放"
'图片说明LabelID
Me.SlideShowExtender1.ImageDescriptionLabelID = Label1.ID
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Me.SlideShowExtender1.PlayInterval = 1000
End Sub
|
请发表评论