I have some fairly simple code here, but I can't for the life of me figure out why it's not working.
I have a page called Update.aspx
which contains the following HTML:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
Non Panel <%= Date.Now.ToLongTimeString%>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lbl" runat="server">Updates in 5</asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
The code behind looks like this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim t As New Timers.Timer
t.Interval = 5000
AddHandler t.Elapsed, AddressOf raiseupdate
t.Start()
End Sub
Private Sub raiseupdate(ByVal sender As Object, ByVal e As System.EventArgs)
sender.stop()
lbl.Text = Date.Now.ToLongTimeString
UpdatePanel1.Update()
End Sub
This is what I'm expecting to happen: The page displays the words "Updates in 5" within the update panel. The timer elapses, calls the raiseupdate()
method, and the update panel update()
method is called which refreshes the content of the update panel.
What actually happens is this: The timer elapses, the update panel update()
method line is reached, but the data never seems to make it back to the page. That is, the words "Updates in 5" are never replaced with the current time.
So I figure I've run into some kind of fundamental misunderstanding about what the update()
method actually does, but I can't figure out where I've gone wrong. What can I do to make this work?