0

I am using updatepanel and timer to display an alert every 15 seconds. It is working fine when I am not clicking anything in the page. It displays alert every 15 seconds. I have a button outside of this updatepanel. Whenever I click this button, the timer resets and it doesn't display alert every 15 seconds. If I stops clicking the button, it starts to display the alert after 15 seconds. BAsically, timer resets the interval when ever I click teh button. I want to display the alert regardless clicking a button or not. Please help me.

in ASPX page

     <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>

In .CS page

public void Timer1_Tick(object sender, EventArgs e) {

       ScriptManager.RegisterClientScriptBlock(UpdatePanel1, typeof(Page), "ToggleScript", "  
          alert('Hello')", true);

    }

1 Answer 1

0

Reason looks lik your button do a post back and your timer in out side the update panel so it will reset.

if you can place your button in to another update panel this will work.

<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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.