Dear asp.net experts,
I'm developing a web-application that will display data derived from a database. As soon as the database was updated (elsewhere on the network) the page should refresh. As I've not found a way to trigger a page refresh from the server side, I have created two updatepanels: one with a timer that periodically checks for updates and one with the label containing the output. Only when the procedure triggered by the timer detects an update in the database, the output panel gets updated.
That in itself is working fine. However, the whole page gets transferred every time the timer triggers, including the lengthy output (which was unchanged) - I have cked that with chrome's "inspect element" function and the network timeline. The update panels got rid of the flickering of a full-refresh of the screen, but as the page will be displayed on a mobile device, data transfer volume must be kept low.
Is there a way I can either trigger the update from the server's end or reduce the amount of data transferred? (Ideally there would only be a few bytes if there was no change.)
The sample project is below.
Thank you for sharing your wisdom :-)
Public Class _default
Protected Sub timerUpdate_Tick(sender As Object, e As EventArgs) Handles timerUpdate.Tick
Dim s As String
' At this point s would actually be created from a database.
' Unless there was a change in the database, s will remain the same in each iteration
s = String.Concat(Enumerable.Repeat("abc ", 10000))
' The right-business is only to remove the timestamp, which is only used anyway in this test
' Usually the code would be
' If s <> lbl1.Text Then
' lbl1.Text = s
' End If
If s <> Right(lbl1.Text, Len(s)) Then
lbl1.Text = Now.ToString & " " & s
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form id="form1" runat="server" title=" ">
<asp:ScriptManager EnablePartialRendering="true" ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="TimerPanel" UpdateMode="Conditional">
<asp:Timer runat="server" ID="timerUpdate" Interval="2000" OnTick="timerUpdate_Tick"></asp:Timer>
<asp:UpdatePanel runat="server" ID="UpdatePanel" UpdateMode="Conditional">
<asp:Label ID="lbl1" runat="server" text="not updated yet"/>