UpdatePanel局部刷新的使用
ScriptManager和UpdatePanel控件联合使用可以实现页面异步局部更新的效果。其中的UpdatePanel就是设置页面中异 步局部更新区域,把你需要异步更新的区域包裹起来,它必须依赖于ScriptManager存在,因为ScriptManger控件提供了客户端脚本生成与管理UpdatePanel的功能。
ScriptManager控件重要的属性:
ScriptManager控件的EnablePartialRendering属性:true-表示实现页面的异步局部更新;false-表示实现全页面的刷新。此属性默认值为true
UpdatePanel控件的UpdateMode属性:Always,UpdatePanel页面上任何一处发生的回发操作都会产生页局部更新;
我们这个让timer不停的运动,就可以实现异步局部刷新,不停的获取当前时间啦
//OnTick 每隔internal毫秒就会回调一次该方法
前端代码
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
后台代码
protected void Page_Load(object sender, EventArgs e)
{
this.Label1.Text = DateTime.Now.ToString();//不能把要定时刷新的数据放在!ispostpack中
}
当前时间: