0

UpdatePanel1 updates every 3 seconds regardless of conditions inside Timer1_Tick. I wanted to only update if x=1. Further explaining: If I completely remove the line UpdatePanel1.Update() and everything inside Timer1_Tick(), then UpdatePanel1 still updates every 3 seconds. The problem is not with where integer x is declared. I'd expect the problem to be within the ASP code.

<asp:ScriptManager runat="server" id="ScriptManager1" />
<div><asp:Timer runat="server" id="Timer1" Interval="3000" OnTick="Timer1_Tick" /></div>
<asp:UpdatePanel runat="server" id="UpdatePanel1" UpdateMode="Conditional" RenderMode="Block">
 <Triggers><asp:AsyncPostBackTrigger ControlID="Timer1" /></Triggers>
 <ContentTemplate>
  <asp:Label id="Label1" runat="server"></asp:Label>
 </ContentTemplate>
</asp:UpdatePanel>

And the vb code..

Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
 'If x=1 Then
  'UpdatePanel1.Update() 'Update only if x=1
 'Else 
 'Do nothing
 'End If
 'Regardless of what is in this subfunction, nothing or the above, Updatepanel updates every 3 seconds
End Sub

February 4th: UpdatePanel1 is still updating/reloading every 3 seconds nonconditionally. Problem is in the ASP code I believe. Answers or ideas are welcome.

  • 3
    Where are you setting and incrementing `x`? – castis Feb 03 '15 at 19:36
  • When I take out UpdatePanel1.Update() then UpdatePanel1 still updates every 3 seconds. Everyoine can forget the condiitonal If x=1 Then update. The problem is elsewhere. – Bryan Bankester Feb 03 '15 at 19:46
  • I'm not sure how much code you've trimmed out of this but you have the code `Label1.Text = MakeDecisions()` but the function `MakeDecisions` doesn't have a return value. – Derek Tomes Feb 03 '15 at 19:52
  • I don't know much about `UpdatePanel`s, but would setting `Label1.Text` cause the panel to update? Should your condition be around that statement instead? – Mark Feb 03 '15 at 19:56
  • @Mark After removing Label1.Text = MakeDecisions, UpdatePanel1 still updates every 3 seconds. Must be problem with my ASP code and how I'm doing the timer. Wait, maybe I should have Triggers. – Bryan Bankester Feb 03 '15 at 20:01
  • Yes, it looks like just having the timer there causes a round-trip to the server every 3 seconds. Not sure if it actually updates anything in the DOM if there are no changes. EDIT - I guess that would be obvious from the docs, if I had read them first, since that is what `Timer` does! :-) – Mark Feb 03 '15 at 20:03
  • I changed the asp code and put the changes beneath original post. Still updates every 3 seconds no matter what's in MakeDecisions() or Timer1_Tick, something or nothing in both. – Bryan Bankester Feb 03 '15 at 21:26
  • Your function `MakeDecisions` should not even compile since you do not return a string in any code path. – Chris Dunaway Feb 04 '15 at 15:01
  • The mystery is still unsolved. Edited code above still updates every 3 seconds unconditionally. @ChrisDunaway It has a return value I just took out to simplify things. If nothing is in MakeDecisions() it still updates every 3 seconds. There, added Return as in my code still updates every 3 seconds. – Bryan Bankester Feb 04 '15 at 15:01
  • The timer is updating every 3 seconds and to fire off the server side event it has to talk to the server and make that call. If you for sure don't want the UI to update then don't actually update those elements in the server side events. – b.pell Feb 04 '15 at 15:10
  • Only when x=1 is when I want UpdatePanel1 to update/reload. I want to check every 3 seconds to see if x=1. But instead, right now UpdatePanel1 is updating/reloading every 3 seconds. – Bryan Bankester Feb 04 '15 at 15:17
  • I simplified the code even more. The problem is with the ASP code. Regardless of what is inside Timer_Tick, UpdatePanel1 just updates every 3 seconds instead of going through the logic inside Timer_Tick to check if x=1. – Bryan Bankester Feb 04 '15 at 15:38
  • UpdateMode is set to "Conditional" although it is updating unconditionally every 3 seconds. ??? – Bryan Bankester Feb 04 '15 at 15:51
  • By its very nature, registering the timer as an `AsyncPostBackTrigger` will cause the UpdatePanel to refresh. If you want to prevent it, you'll need to interact with it on the client side (via JavaScript). However, that's probably going to be difficult because you're getting into the inner working of the UpdatePanel. A better solution would be to switch to AJAX polling and ASP.NET Web API based solution (or SignalR). In that way, you'll have precise control over when it talks to the server. – mason Feb 04 '15 at 21:13
  • possible duplicate of [How to Control or Stop Partial Post Back in Update Panel](http://stackoverflow.com/questions/5803630/how-to-control-or-stop-partial-post-back-in-update-panel) – mason Feb 04 '15 at 21:23
  • I want whatever is inside Timer1_Tick to happen on every Timer1's Interval and no updating of UpdatePanel1 unless told to inside Timer1_Tick. That's not something really easy to do? If not, forget the UpdatePanel existing. Now, I just want a function like Timer1_Tick called every X seconds using an ASP Timer. How can I do that? – Bryan Bankester Feb 05 '15 at 20:36

0 Answers0