Live Demo Source Code
While browsing the ASP.NET Forums I came to a thread with a request for implementing a polling scheme with two UpdatePanels.
In the specific scenario, we have a Timer control (Timer1) that is acting as a trigger for two UpdatePanels, let's say UpdatePanel1 and UpdatePanel2.
While UpdatePanel1 is always polling based on the time interval set on Timer1, UpdatePanel2 starts polling only when a button is clicked inside UpdatePanel1. Similarly, clicking another button stops UpdatePanel2 from updating.
You may want to look at the live demo to better understand the requirement.
The first thing I thought was to programmatically add and remove from the second UpdatePanel the trigger pointing to Timer1 but this is not the best approach because a dynamic trigger should be added on every request and this leads to very ugly code.
In the implementation, I've used a single trigger in UpdatePanel1 pointing to Timer1 and a server side flag called EnablePolling to determine if UpdatePanel2 is polling. Then, in the Tick event handler for Timer1, UpdatePanel2 is programmatically updated with a call to the Update method.
Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!