Update中使用Timer的方法:

本文探讨了ASP.NET页面中Timer控件的使用方法,包括如何在页面外和页面内设置定时器,以及如何通过触发器实现异步回送和整页回送的功能。
摘要由CSDN通过智能技术生成


(1):Timer在UpdatePanel外面的时候

 <%@ 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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
        
              <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="2000"   >
            </asp:Timer>
            
             <asp:Timer ID="Timer2" runat="server" OnTick="Timer3_Tick" Interval="3000"   >
            </asp:Timer>
        <div  >

            
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">

    <ContentTemplate >

           


 <asp:Button ID="Button1" runat="server" Text="异步回送" OnClick="Button1_Click"/>&nbsp;&nbsp;

                    <asp:Button ID="Button2" runat="server" Text="整页回送" OnClick="Button2_Click"/><br />

                    <br />

                    <asp:Label ID="Label1" runat="server" Text="当前时间1" Font-Bold="True" Font-Size="Large"></asp:Label>
                    </div>

                    <asp:Label ID="Label3" runat="server" Text="当前时间2" Font-Bold="True" Font-Size="Large"></asp:Label>
                 
  
      

</div>

 


    </ContentTemplate>

    <Triggers>

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

        <asp:PostBackTrigger ControlID="Button2"  />

    </Triggers>

</asp:UpdatePanel>
                          <br />

 
        </div>
    </form>
</body>
</html>

(2)在里面的

<%@ 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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
       

      <div  >     
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">

    <ContentTemplate >

            
              <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="2000"   >
            </asp:Timer>
           
                    <asp:Label ID="Label1" runat="server" Text="当前时间" Font-Bold="True" Font-Size="Large"></asp:Label>
    </ContentTemplate>

   
</asp:UpdatePanel>
                          <br />

 
        </div>
    </form>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值