zoukankan      html  css  js  c++  java
  • 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秒执行一次。

            }

  • 相关阅读:
    提高你的Java代码质量吧:使用构造函数协助描述枚举项
    Python文件或目录操作的常用函数
    汉语-词语:胸怀
    汉语-词语:胸襟
    汉语-词语:谋略
    汉语-词语:气量
    植物-常见树木:刺槐
    植物-常见树木:楝
    HDU 2255 奔小康赚大钱 KM算法题解
    Dozer--第三方复制工具,哎哟,还不错!
  • 原文地址:https://www.cnblogs.com/nangong/p/Ajax.html
Copyright © 2011-2022 走看看