I have developed a vb.NET dll that raises events which I want to handle from an asp application. So far, I managed to handle the events from the asp application, store event's data in session and then with an asp timer and an updatePanel
control, I perform updates to the desired asp controls by reading session's data in each timer interval. But, if I try to update the asp controls directly from inside the code that handles an event, without using a timer and session, controls do not update. As suggested from a previous post, this happens because the code executes on the server. In a few words:
Dll raises event
Asp/vb code handles the event and store its data in session
Timer executes every second, reads session's data and updates controls
So my question is this.
- Is there a better approach to update the asp controls, rather than using a timer that reads every second session variables?
- I was wondering if this issue relies on my DLL, not raising events asynchronously? Or it's just how asp/web works and there is no other workaround?
Note: I have done a lot of research on what is the best way to raise an event asynchronously in a vb.NET dll. So far I came across to the Event-based Asynchronous Pattern Overview, to Raising events asynchronously and Do events work if raised asynchronously?. From all this the Raising events asynchronously looks to me the easiest approach but it's outdated and I am having problems to implement and test it in framework 4.0. But before starting to mess around with all this I wanted a second opinion.
dll code (MyDllEvents.cls)
Public Event MyEvent(ByVal message As String)
Private Sub RaiseMyEvent(ByVal message As String)
RaiseEvent MyEvent(message)
End Sub
Asp & vb code inside Asp application
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
Private withevents o As new MyDllEvents.cls
Protected Sub o_MyEvent(message As String) Handles o.MyEvent
Label1.Text = message 'not updating
UpdatePanel1.Update() 'contains the Label1 control
End Sub