如何使用UpdatePanel的计时器控件定期更改图像 [英] How To Change An Image Periodically With Timer Control Using UpdatePanel

查看:87
本文介绍了如何使用UpdatePanel的计时器控件定期更改图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上,需要显示一张图片,并且该图片应定期更改.
我使用了以下代码.

In my website, an image is needed to show and should change periodically .
I used the below code.

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" OnTick="gettickvalue" Interval="2000">
</asp:Timer>
<asp:UpdatePanel ID="BannerPanel" runat="server" UpdateMode="Conditional">
<Triggers >
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Image ID="imgBanner" ImageUrl="~/images/banner_1.gif" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>





在代码部分中添加以下行.





In the code section add the following lines.

protected void gettickvalue(object sender, EventArgs e)
{
Random RandomNumber = new Random();
int n = RandomNumber.Next(1, 9);
imgBanner.ImageUrl = System.String.Concat("images/banner_", n.ToString(), ".gif");
}


* ------ *
但是我首先可以看到图像正在显示,经过特定时间延迟的图像改变了,但是立即又出现了.所以看不到任何图像.
我将间隔增加到5000或以上,但仅更改了图像即将到来的时间.
如何设置图像显示5-6秒.


*------*
But I can see in first a image is showing, after particular time delay image changed but immediately come another .So Can''t see any image.
I increased interval to 5000 or above , but it is changed image coming time only.
How can set image appear 5-6 seconds .

推荐答案

http://www.4guysfromrolla.com/articles/091907-1.aspx [
http://www.4guysfromrolla.com/articles/091907-1.aspx[^]

Please read this article I think it will help you


尝试将其设置为50000或60000,因为时间以毫秒为单位.
try to set it to 50000 or 60000 since the time is in millisec.


我的文件是不是gif格式.所有文件均为jpg格式.我将类型更改为jpg.然后文件正确显示
My files are in not in gif format. All files are jpg format. I changed type to jpg . Then files showing correctly


这篇关于如何使用UpdatePanel的计时器控件定期更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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