views:

35

answers:

1

I've got a problem with the timer in asp.net ajax. The timer needs to trigger every second so I put the delay of the timer (don't know the real name atm) at 1000.

Now when I put this timer inside an UpdatePanel it doesn't really trigger every second because the timer also gets updated in the UpdatePanel. But when I put the timer outside the update panel it keeps kinda refreshing the page, so whenever I put a button on the same page I need to press and release this button within 1 second else it gets refreshed.

Also I saw that even outside of the UpdatePanel the timer isn't a real second.

Any solutions?

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

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" Interval="100" ontick="Timer1_Tick">
            </asp:Timer>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <br />
            \<asp:ListBox ID="ListBox1" runat="server" Height="182px" Width="193px">
            </asp:ListBox>
            <asp:ListBox ID="ListBox2" runat="server" Height="179px" Width="189px">
            </asp:ListBox>
            <br />
        </ContentTemplate>
    </asp:UpdatePanel>

</div>
<p>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</p>
</form>

This timer doesn't really go every second. In the boxes below I put an datetime with seconds whenever the timer updates. And it only updates like 3 times when I got 100 delay on the timer inside the update panel. When placed outside it is a little more then 3 times but still not the 10/9 times you should expect.

A: 

In the code you pasted the interval is set to 100 and not 1000. 100 is 1/10 of a second.

zincorp
True, and as explained it only triggers 3 to 4 times in a second.
Julian