Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto refresh Updatepanel every 5 seconds

I have an update panel in my master page in a webforms application, now I have set this update panel to refresh every 5 seconds so as to reflect an updated count of row items. Some thing like the number of new messages. My questions are:

  • Is this the right way to reflect for new row item count on my page every 5 seconds and
  • Will this degrade my applications performance in the long run in what ever way by constantly refreshing the update panel frequetly.

My label is getting its value from an ExecuteReader query from my code-behind.

like image 249
Marcos J.D Junior Avatar asked Sep 09 '17 08:09

Marcos J.D Junior


1 Answers

Yes, you can refresh after five seconds or on any interval with Timer control without degrading performance.

Here's an example with an interval:

HTML Markup:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>      
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <!-- your controls in panel -->
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers> 
</asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick"></asp:Timer>

Code-Behind:

protected void Timer1_Tick(object sender, EventArgs e)
{
    // your stuff to refresh after some interval
}
like image 186
youpilat13 Avatar answered Sep 22 '22 07:09

youpilat13