首先加入UpdatePanel

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

//注:UpdateMode为更新模式,设置此属性表示只刷新UpdatePanel中的部分,若不加此属性,默认为Always,刷新整个页面。

//OnTick为时间促发函数(后台函数),Interval为时间5000为5秒,即每5秒后促发此函数
                            </asp:Timer>

<在此添加需要刷新的内容>

         
                      <Triggers>//此处相当于关联。简单解释就是通过Timer1来促发UpdatePanel的刷新
                                      <asp:AsyncPostBackTrigger ControlID="Timer1 EventName="Tick" />
                      </Triggers>

         <ContentTemplate>

          <asp:Timer ID="Timer1 runat="server" Interval="5000" OnTick="Timer2_Tick">
                         </ContentTemplate>

      
                    </asp:UpdatePanel>

后台代码:

即刚才的TIMER_TICK。

protected void Timer1_Tick(object sender, EventArgs e)
    {
         此处写上需要在5秒后做的事情。
   }

 ------------------------------------------------------------------------------------------------------------------------------------------

Timer,顾名思义即是一个定时器控件,通过它可以在指定时间间隔内刷新UpdatePanel或整个页面。该控件包含一个重要的属性  Interval ,用来定义刷新的时间间隔,单位为毫秒。另外包含一个Tick 事件,可以用来定义服务端行为。一个页面可以定义多个Timer控件来为不同的UpdatePanel指定刷新间隔,也可以多个UpdatePanel共用一个Timer。

Timer控件可以在UpdatePanel内声明,这时自动作为该UpdatePanel的Trigger:

ASP.NET-Code:
<asp:ScriptManager runat="server" id="ScriptManager1" /> <asp:UpdatePanelrunat="server" id="UpdatePanel1"     UpdateMode="Conditional">   <contenttemplate>    <asp:Timer id="Timer1" runat="server"       Interval="120000"      OnTick="Timer1_Tick">     </asp:Timer>   </contenttemplate> </asp:UpdatePanel>

也可以在UpdatePanle外声明,此时如果要刷新该UpdatePanel,则必须指定Timer为它的Trigger:

ASP.NET-Code:
<asp:ScriptManager runat="server" id="ScriptManager1" /> <asp:Timer ID="Timer1"runat="server" Interval="120000"   OnTick="Timer1_Tick"> </asp:Timer> <asp:UpdatePanelID="UpdatePanel1" runat="server">   <Triggers>     <asp:AsyncPostBackTriggerControlID="Timer1"         EventName="Tick" />     </Triggers>     <ContentTemplate>       <asp:Label ID="Label1" runat="server" ></asp:Label>   </ContentTemplate></asp:UpdatePanel>

在本例中我们可以定义他的Tick事件,用来显示最近刷新的时间

C#-Code:
protected void Timer1_Tick(object sender, EventArgs e) {      Label1.Text = DateTime.Now.ToString(); }

注:Timer控件与UpdatePanel一样均需要ScriptManager控件的支持。

AJAX中UPDATEPANEL配合TIMER控件实现局部无刷新的更多相关文章

  1. winform中如何使用timer控件实现欢迎(初始加载)窗口

    第一步.新建窗体项目命名为:TestWelcomeFrm,如下图: 第二步.在新项目中,增加欢迎窗口,命名为WelFrm,整个项目目录如下: 第三步.修改program.cs中启动代码如下: WelF ...

  2. Asp:Button控件onclick事件无刷新页面提示消息

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

  3. Dev控件用法 aspxTreeList 无刷新 aspxGridView 数据

    主要是利用 ASPxTreeList 点击事件回发服务器进行数据重新绑定 ASPxTreeList: <SettingsBehavior ExpandCollapseAction="N ...

  4. ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件

    本文将使用Timer控件更新两个UpdatePanel控件,Timer控件将放在UpdatePanel控件的外面,并将它配置为UpdatePanel的触发器,翻译自官方文档. 主要内容 在多个Upda ...

  5. ASP.NET AJAX入门系列(10):Timer控件简单使用

    本文主要通过一个简单示例,让Web页面在一定的时间间隔内局部刷新,来学习一下ASP.NET AJAX中的服务端Timer控件的简单使用. 主要内容 Timer控件的简单使用 1.添加新页面并切换到设计 ...

  6. 谨记给UpdatePanel中动态添加的控件赋ID

    原文:谨记给UpdatePanel中动态添加的控件赋ID 昨天下定决 心对上次做的布局编辑器控件加以改进,其中最主要变化的就是要完全使用ASP.NET AJAX!但是很遗憾,虽然耳闻已久,但目前对AS ...

  7. C# windows服务:C#windows服务中的Timer控件的使用

    C# windows服务程序中的Timer控件的使用问题是如何解决的呢? 今天和同事一起研究了下C# windows服务程序中的Timer控件的使用的写法. 我们在建立一个C# windows服务程序 ...

  8. 关于c#中的Timer控件的简单用法

    Timer控件主要会用到2个属性一个是Enabled和IntervalEnabled主要是控制当前Timer控件是否可用timer1.Enabled=false;不可用timer1.Enabled=t ...

  9. winform用户控件、动态创建添加控件、timer控件、控件联动

    用户控件: 相当于自定义的一个panel 里面可以放各种其他控件,并可以在后台一下调用整个此自定义控件. 使用方法:在项目上右键.添加.用户控件,之后用户控件的编辑与普通容器控件类似.如果要在后台往窗 ...

随机推荐

  1. Jquery_JQuery之DataTables强大的表格解决方案

    1.DataTables的默认配置 $(document).ready(function() { $(‘#example’).dataTable(); } ); 示例:http://www.guoxk ...

  2. Graph database_neo4j 底层存储结构分析(6)

    3.6  Node 数据存储 neo4j 中, Node 的存储是由 NodeStore 和 ArrayPropertyStore 2中类型配合来完成的. node 的label 内容是存在Array ...

  3. spark-submit [options]

    执行时需要传入的参数说明如下: Usage: spark-submit [options] <app jar | python file> [app options] 参数名称 含义 -- ...

  4. SparkContext.setCheckpointDir()

    class SparkContext extends Logging with ExecutorAllocationClient Main entry point for Spark function ...

  5. #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif

    这样的代码到底是什么意思呢?首先,__cplusplus是cpp中的自定义宏,那么定义了这个宏的话表示这是一段cpp的代码,也就是说,上面的代码的含义是:如果这是一段cpp的代码,那么加入" ...

  6. uva729

    /*题目一大堆,其实意思就是长度为n个二进制数,里面有h个1,将这个二进制数进行全排列,然后输出*/ #include"iostream" #include"algori ...

  7. 设计模式(Design Patterns)

    设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...

  8. SDUT 2610 Boring Counting(离散化+主席树区间内的区间求和)

    Boring Counting Time Limit: 3000MS Memory Limit: 65536KB Submit Statistic Discuss Problem Descriptio ...

  9. PHP 支持中文目录和文件的的遍历:文件编码转换

    在使用 readdir() 遍历指定目录时,使中文目录和文件名都正常显示需要使用 iconv() 进行文件编码转换: <?php header("Content-type:text/h ...

  10. jQuery 两种方法实现IE10以下浏览器的placeholder效果

    /* ** jQuery版本:jQuery-1.8.3.min.js ** 测试的浏览器:IE8,IETester下的IE6-IE9** Author:博客园小dee */ placeholder是H ...