With intervals that close together, could you be running into issues with simultaneous requests? What happens if you make one timer 10000 and the other 20000?
I think the problem is with update panel that more one update cannot work simultaneously (In async postback). Rewrite your code with window.setInterval and WebService/PageMethod call.
No matter how separate I set the timers this will not work.
I've tried the webservice approach but this does not allow me to access and modify the controls on the page so seems this approach will not work.
EDIT -----
My real scenario is not that simple as I posted above (this was just an easy sample to reproduce the problem). In fact what I have is datalist with I rebind on "tick".
Interesting problem.
What's happening is that the Timer control uses a hidden span to store its state information. Since both UpdatePanels default to an UpdateMode of Always, the hidden span in the panel with the longer time was being overwritten with its initial state on each partial postback of the other panel. This was resetting the longer timer back to 0 every time the shorter timer ticked, so the longer one was never able to fire.
Setting the UpdateMode of both UpdatePanels to Conditional fixes it. Or, place the Timers outside the UpdatePanels and then set them as async triggers for their corresponding UpdatePanels.
I hate to say so but ... it's still not working
Here is my actual code:
<asp:Timer ID="timer" runat="server" OnTick="timer_Tick" /><asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional"><Triggers><asp:AsyncPostBackTrigger ControlID="timer" EventName="Tick" /></Triggers><ContentTemplate><asp:HiddenField ID="iterator" runat="server" /><asp:Panel runat="server" ID="pnlHeight"><asp:DataList ID="dlList" runat="server" RepeatDirection="Horizontal"Width="100%" ShowFooter="False" ShowHeader="False" HorizontalAlign="center" BorderStyle="none"BorderWidth="0" OnItemCreated="dlList_ItemCreated" OnItemDataBound="dlList_ItemDataBound"><ItemStyle HorizontalAlign="center" VerticalAlign="middle" /><ItemTemplate><asp:PlaceHolder ID="plTemplate" runat="server"></asp:PlaceHolder></ItemTemplate></asp:DataList></asp:Panel></ContentTemplate></asp:UpdatePanel>The items on the datalist are injected dinamically but this is not the issue. As you can see I have both Conditional and Triggers but still same behaviour: only one timer working.
Hmm, when I changed your first code snippet to this:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" />
<asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:TextBox ID="TextBox2" runat="server" />
<asp:Timer ID="Timer2" runat="server" Interval="2000" OnTick="Timer2_Tick" />
</ContentTemplate>
</asp:UpdatePanel>
I started getting a's and b's at the correct intervals.
Could you post full code for what you have that isn't working, including both UpdatePanels and Timers?
No comments:
Post a Comment