views:

77

answers:

4

I use c# and usually program winform/desktop applications. But; now I'm asked to develop some ASP.Net projects. So here goes my newbie question:

I'm developing this project for device (lets say) 'Protoype X' and it has manufacturer provided .Net api. This api fires events (which I shoud subscribe to) upon receiving some special -signal- from the device in real world. What I want/asked to do is, update the asp page (which the user sees) with proper information when this event is fired. By update I mean also refreshing user's page if possible at all... How do I do this in asp.net?

+3  A: 

You cannot trigger a page update from the server side. What you must do is use a timer on the client side (javascript) to refresh the page (or get the new data via AJAX) on a regular interval.

tekBlues
+1  A: 

You can force the page to refresh by using a meta tag, or javascript. Or AJAX.

Tundey
+1  A: 

Web aps follow a request-response architecture so you can't really (well, easily) have server initiated messages from client to server.

You can use a polling architecture. At its very simplest, you could simply have the page refresh every X seconds/minutes to check for changes. This may be a bit ugly.

A more user friendly approach might be to use the XMLHTTP object to poll for changes every few seconds and refresh the page when a change is detected. You could create an HTTP Handler on the server side that simply have the date/time of last change and have a javascript check this every few seconds and when a change occurrs, refresh the page.

James Conigliaro
A: 

You've got another problem here that has not been addressed. If you've got more than one copy of this device, then how will you associate each device with the user or users who are using it or monitoring it?

I suggest you write the "device-access" part of this system in a Windows Service. Let it maintain connection to the devices, keep track of their state, respond to events, etc. Let it maintain a set of data about each device, either in-memory or in a database.

The web application could communicate with the service through a WCF service hosted in the Windows Service. There could be one WCF call that asks if anything has changed, and another call to get the changes. The first could be called relatively frequently, through AJAX or meta refresh. The latter would only be called when a change had been seen.

John Saunders