• C# 一个页面,多个Updatepannel,多个Timer


    这几天在搞一个项目,其中一个页面里面有好几组数据要定时刷新,但是,每一组数据要刷新的时间不一样,所以就需要用到多个定时器。本人刚工作不久,对Js 的Ajax不太了解,反而对微软的那个Ajax相对了解一点。但是,发现使用多个Timer和Updatepannel的时候,数据无法直接按照我设定的时间去刷新,后来发现,原来是要增加一个UpdateMode="Conditional"来控制,现在贴上代码,供大伙儿互相学习,如果您有比我这个更好点的,请多多指教,谢谢。

     前台代码:

    <asp:ScriptManager ID="ScriptManager1" runat="server" />  

           <div>            

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">         

            <ContentTemplate>            

             <asp:TextBox ID="TextBox1" runat="server" Width="306px"></asp:TextBox>    

                     <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">     

                    </asp:Timer>        

             </ContentTemplate>      

           </asp:UpdatePanel>       

      </div>

        </div>

        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">

            <ContentTemplate>    

             <asp:TextBox ID="TextBox2" runat="server" Width="304px"></asp:TextBox>

                <asp:Timer ID="Timer2" runat="server" Interval="10000" ontick="Timer2_Tick">     

            </asp:Timer>

            </ContentTemplate>  

       </asp:UpdatePanel>

    后台代码:

    protected void Timer1_Tick(object sender, EventArgs e)    

         {            

                TextBox1.Text = DateTime.Now.ToString(); //这里是一秒执行一次。

            }

    protected void Timer2_Tick(object sender, EventArgs e)   

          {          

                 TextBox2.Text = DateTime.Now.ToString(); //这里可以改成你要执行的方法,我这里用时间来代替,比较直观,10秒执行一次。

            }

     





  • 相关阅读:
    重新整理数据结构与算法(c#)—— 树的节点删除[十八]
    重新整理数据结构与算法(c#系列)—— 树的前中后序遍历查找[十七]
    重新整理数据结构与算法(c#系列)—— 树的前中后序遍历[十六]
    js es6 标签模板还原字符串
    MVC过滤器简单刨析
    MVC 测试action的运行速度
    MVC如何创建区域
    软件——IDEA 超实用使用技巧分享
    前端——Vue-cli 通过UI页面创建项目
    软件——IDEA中如何去掉警告虚线
  • 原文地址:https://www.cnblogs.com/nangong/p/3948a57e197e8b30230096f31bca174b.html
Copyright © 2020-2023  润新知