计时器 Tick 事件未触发 [英] Timers Tick event not firing
本文介绍了计时器 Tick 事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个简单的代码,我在其中添加了一个计时器并生成了滴答事件,但该事件没有触发.
There is a simple code in which I added a timer and generated tick event but the event is not firing.
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" Enabled="True" EnableViewState="True" ViewStateMode="Inherit" ClientIDMode="Inherit"></asp:Timer>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
setImageurl();
//Timer1.Tick += new EventHandler(Timer1_Tick);
//Timer1.Interval = 1000;
}
}
void setImageurl()
{
Random _rand = new Random();
int i = _rand.Next(1, 4);
Image1.ImageUrl = "~/ImagesSlideshow/" + i.ToString() + ".jpg";
}
protected void Timer1_Tick(object sender, EventArgs e)
{
setImageurl();
}
我不知道为什么会这样.帮帮我.
I dont know why this is happening. Help me out.
推荐答案
在 ScriptManager
上设置 EnableCdn="true"
就可以了,只是在我的侧面:
Set EnableCdn="true"
on the ScriptManager
and it will work, just tried it on my side:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableCdn="true"></asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1000"></asp:Timer>
<asp:Image ID="Image1" runat="server" />
</form>
这篇关于计时器 Tick 事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文