日期:2014-05-19  浏览次数:20378 次

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事件,而且,每个事件都是使用线程池的。