首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

asp.net ajax 中timer 控件的tick事件为什么不能触发(ajax新手)解决方法

2012-03-04 
asp.net ajax 中timer 控件的tick事件为什么不能触发(ajax新手)这是页面bodyformid form1 runat s

asp.net ajax 中timer 控件的tick事件为什么不能触发(ajax新手)
这是页面
<body>
        <form   id= "form1 "   runat= "server ">
                <asp:ScriptManager   ID= "ScriptManager1 "   runat= "server ">
                </asp:ScriptManager>
                <asp:UpdatePanel   ID= "UpdatePanel1 "   runat= "server ">
                        <ContentTemplate>
                                &nbsp; <asp:Timer   ID= "Timer1 "   runat= "server "   Interval= "1000 "   OnTick= "Timer1_Tick ">
                                </asp:Timer>
                                <asp:Label   ID= "Label1 "   runat= "server "   Text= "Label "   Width= "95px "> </asp:Label>
                        </ContentTemplate>
                </asp:UpdatePanel>
                <asp:Label   ID= "Label2 "   runat= "server "   Text= "Label "   Width= "94px "> </asp:Label>
       
             

        </form>
</body>
这是tick事件
    protected   void   Timer1_Tick(object   sender,   EventArgs   e)
        {
                this.Label1.Text   =   "text   changed   on   "   +   System.DateTime.Now.ToString();
        }

[解决办法]
用错了。如果你确实用的Timer.Tick事件,那你一定是用了System.Windows.Forms.Timer。这个是给WinForm用的。这个东西是单线程的。

你的是WebForm,应该用,System.Timers.Timer。这个东西触发Elapsed事件,而且,每个事件都是使用线程池的。

热点排行