Take the 2-minute tour ×

I wonder if the following is possible:

I have a dll that I have referenced in my web site. This dll makes a remote socket connection. The socket connection is waiting in the background and the dll reports back data through events after the socket has received some data.

The connection is opened during load of page.

Now, I would, for example, like to update a label on the page when new data has arrived.

I am not sure how this would work. I assume that I could set some kind of timer on page that updates a control but it does not seem "optimal" as I already call code behind through my events. "Optimally" the UpdatePanel or whatever updates the interface would wait for events and "update" when events has occurred and not based on time.

My question is - is this possible?

share|improve this question
It's easier to load the page on the client then initiate the call to the server via AJAX, letting the page method wait (the page has loaded but you could display a little "loading" symbol somewhere) and then, when it receives the response from the server, update. This is a good use case for Page Methods - see ajax.asp.net/docs/tutorials/…. Once your original page has been delivered, you shouldn't really have anything in it to keep it alive on the web form/code behind side - it should be request-response based. –  dash Feb 24 '12 at 13:03
add comment

3 Answers

up vote 1 down vote accepted

You can use techniques called "long pulling" or "web sockets".

There are libraries, like SignalR that can help you.

They generally use web sockets when client's browser supports and long pulling when not.

Using these libraries you can "push" commands/data from server to client's browser, just as you want.

share|improve this answer
add comment

Server cannot push the client, this is the rule how web works. There are two possible ways to complete your task.

  1. Put timer on the page and make requests on server too see, if something changed
  2. Open long pulling connection between client and server, like facebook does. That listens
    to the events and gets data from the server. It can be, for example xmpp or any other.
share|improve this answer
add comment

You should think about turning this around; rather than initiate the call from the code behind asynchronously and then update the client, you should deliver your original page to the client.

Once the page has been loaded client side, you can make an AJAX call to the server to retrieve the data you want - and display a little "I'm loading" symbol while this happens.

Page Methods are ideal for this.

The classic ASP.Net web page is supposed to last for the duration of the users request. When a postback happens, it effectively rebuilds the state of the call from the user's viewstate, session and any other state you've maintained. It never cares if the user goes away, for example (although it might feel a bit lonely).

Having it hang around for longer is problematic in a number of ways, however, you can implement client callbacks. However, although the server initiates this, the client manages the lifecycle, so it's analogous to page methods.

share|improve this answer
add comment

Your Answer


