如何避免asp.net/ajax中的计时器重置

如何避免asp.net/ajax中的计时器重置,asp.net,timer,asp.net-ajax,Asp.net,Timer,Asp.net Ajax,我使用updatepanel和计时器每15秒显示一次警报。当我没有点击页面中的任何内容时,它工作正常。它每15秒显示一次警报。我在更新面板外面有一个按钮。每当我点击这个按钮,计时器就会重置,并且不会每15秒显示一次警报。如果我停止单击该按钮,它将在15秒后开始显示警报。基本上,每当我点击按钮时,定时器就会重置间隔。无论是否单击按钮,我都要显示警报。请帮帮我 在ASPX页面中 <asp:ScriptManager ID="ScriptManager1" runat="server"

我使用updatepanel和计时器每15秒显示一次警报。当我没有点击页面中的任何内容时,它工作正常。它每15秒显示一次警报。我在更新面板外面有一个按钮。每当我点击这个按钮,计时器就会重置,并且不会每15秒显示一次警报。如果我停止单击该按钮,它将在15秒后开始显示警报。基本上,每当我点击按钮时,定时器就会重置间隔。无论是否单击按钮,我都要显示警报。请帮帮我

在ASPX页面中

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

       </asp:ScriptManager>

        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"      
         ViewStateMode="Enabled">
  <Triggers>
  <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
   </Triggers>
 </asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="15000" OnTick="Timer1_Tick">
</asp:Timer>

原因看起来像是你的按钮做了回发,你的定时器在更新面板的外面,所以它会重置

如果你能把你的按钮放在另一个更新面板上,这就行了

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ViewStateMode="Enabled">
    <ContentTemplate>
        <asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="Timer1_Tick">
        </asp:Timer>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    </ContentTemplate>
</asp:UpdatePanel>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ViewStateMode="Enabled">
    <ContentTemplate>
        <asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="Timer1_Tick">
        </asp:Timer>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    </ContentTemplate>
</asp:UpdatePanel>