日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

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

發(fā)布時(shí)間:2025/5/22 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
本文將使用Timer控件更新兩個(gè)UpdatePanel控件,Timer控件將放在UpdatePanel控件的外面,并將它配置為UpdatePanel的觸發(fā)器,翻譯自官方文檔。<?XML:NAMESPACE PREFIX = O />

?

主要內(nèi)容

??? 在多個(gè)UpdatePanel中使用Timer控件

?

1.添加一個(gè)新頁面并切換到設(shè)計(jì)視圖。

2.如果頁面沒有包含ScriptManager控件,在工具箱中的AJAX Extensions標(biāo)簽下雙擊ScriptManager控件添加到頁面中。

<?XML:NAMESPACE PREFIX = V />

3.雙擊Timer控件添加到Web頁面中。Timer控件可以作為UpdatePanel的觸發(fā)器不管它是否在UpdatePanel中。

4.雙擊UpdatePanel控件添加一個(gè)Panel到頁面中,并設(shè)置它的UpdateMode屬性值為Conditional

5.再次雙擊UpdatePanel控件添加第二個(gè)Panel到頁面中,并設(shè)置它的UpdateMode屬性值為Conditional

6.在UpdatePanel1中單擊,并在工具箱中Standard標(biāo)簽下雙擊Label控件添加到UpdatePanel1中。

7.設(shè)置Label控件的Text屬性值為“UpdatePanel1 not refreshed yet”。

8.添加Label控件到UpdatePanel2

9.設(shè)置第二個(gè)Label控件的Text屬性值為“UpdatePanel2 not refreshed yet”。


10
.設(shè)置Interval屬性為10000Interval屬性的單位是毫秒,所以我們設(shè)置為10000,相當(dāng)于10秒鐘刷新一次。

11.雙擊Timer控件添加Tick事件處理,在事件處理中設(shè)置Label1Label2Text屬性值,代碼如下。 public?partial?class?_Default?:?System.Web.UI.Page

{

????
protected?void?Page_Load(object?sender,?EventArgs?e)

????
{

????}


????
protected?void?Timer1_Tick(object?sender,?EventArgs?e)

????
{

????????Label1.Text?
=?"UpdatePanel1?refreshed?at:?"?+

??????????DateTime.Now.ToLongTimeString();

????????Label2.Text?
=?"UpdatePanel2?refreshed?at:?"?+

??????????DateTime.Now.ToLongTimeString();

????}


}
12.在UpdatePanel1UpdatePanel2中添加Timer控件作為AsyncPostBackTrigger,代碼如下: <Triggers>

??
<asp:AsyncPostBackTrigger?ControlID="Timer1"?EventName="Tick"?/>

</Triggers> 全部完成后ASPX頁面代碼如下:

<%@?Page?Language="C#"?AutoEventWireup="true"?CodeFile="Default.aspx.cs"?Inherits="_Default"?%>

?

<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.1//EN"?"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html?xmlns="http://www.w3.org/1999/xhtml">

<head?id="Head1"?runat="server">

????
<title>Untitled?Page</title>

</head>

<body>

????
<form?id="form1"?runat="server">

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

????????
<div>

????????????
<asp:Timer?ID="Timer1"?OnTick="Timer1_Tick"?runat="server"?Interval="10000">

????????????
</asp:Timer>

????????
</div>

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

????????????
<Triggers>

????????????????
<asp:AsyncPostBackTrigger?ControlID="Timer1"?EventName="Tick"?/>

????????????
</Triggers>

????????????
<ContentTemplate>

????????????????
<asp:Label?ID="Label1"?runat="server"?Text="UpdatePanel1?not?refreshed?yet."></asp:Label>

????????????
</ContentTemplate>

????????
</asp:UpdatePanel>

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

????????????
<Triggers>

????????????????
<asp:AsyncPostBackTrigger?ControlID="Timer1"?EventName="Tick"?/>

????????????
</Triggers>

????????????
<ContentTemplate>

????????????????
<asp:Label?ID="Label2"?runat="server"?Text="UpdatePanel2?not?refreshed?yet."></asp:Label>

????????????
</ContentTemplate>

????????
</asp:UpdatePanel>

?

????
</form>

</body>

</html>
13.保存并按Ctrl + F5運(yùn)行。

14.等待10秒鐘后兩個(gè)UpdatePanel都刷新后,Label中的文本都變成了當(dāng)前時(shí)間。

?

[翻譯自官方文檔]

轉(zhuǎn)載于:https://blog.51cto.com/terrylee/67721

總結(jié)

以上是生活随笔為你收集整理的ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。