欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net中Timer無(wú)刷新定時(shí)器的實(shí)現(xiàn)方法

 更新時(shí)間:2014年08月25日 11:34:41   投稿:shichen2014  
這篇文章主要介紹了asp.net中Timer無(wú)刷新定時(shí)器的實(shí)現(xiàn)方法,是一個(gè)非常具有實(shí)用價(jià)值的技巧,需要用到Ajax技術(shù),需要的朋友可以參考下

 本文實(shí)例講述了asp.net中Timer無(wú)刷新定時(shí)器的實(shí)現(xiàn)方法。Timer控件要實(shí)現(xiàn)無(wú)刷新,得用到ajax技術(shù),這里使用VS2008自帶的ajax技術(shù)。
 
 首先得添加一個(gè)ScriptManager控件,然后再添加一個(gè)UpdatePanel用于存放Timer控件內(nèi)容的,就可以實(shí)現(xiàn)無(wú)刷新了。下面是詳細(xì)的內(nèi)容:

一、前臺(tái)代碼如下:

<form id="form1" runat="server">
  <asp:ScriptManager ID="ScriptManager1" runat="server">
  </asp:ScriptManager>
      <asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
        <asp:Timer ID="Timer1" runat="server" Interval="60000" ontick="Timer1_Tick">
        </asp:Timer>
      </ContentTemplate>
      </asp:UpdatePanel>
</form>

記得ScriptManager 一定要放在<form>標(biāo)簽內(nèi),可以放在任意地方。而添加UpdatePanel 控件后,要用到它一個(gè)很重要的屬性ContentTemplate,要不然就無(wú)法實(shí)現(xiàn)無(wú)刷新效果。在這里我們?cè)O(shè)置6秒定時(shí)觸發(fā)事件一次。

二、后臺(tái)代碼如下:

protected void Page_Load(object sender, EventArgs e)
{}
protected void Timer1_Tick(object sender, EventArgs e)
{
//這里可以操作你想做的事情,比如定時(shí)查詢(xún)數(shù)據(jù)庫(kù)
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('Hello‘);", true);
}

希望本文所述實(shí)例對(duì)大家asp.net程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論