开发者

How do you push an update to a non-HTML5 browser?

We are considering a web application to provide users with frequent updates to system data. Initially, the data would be limited to system pressure, flow, etc. but the concept could apply to many areas of our business. The data is stored in SQL Server.

The question is, how do we force a table on a webpage to update when new data is inserted into the database. For example, a p开发者_开发知识库ump reports a new flow value. The updates to the database can be throttled but realistically we're looking at a new update every minute or two for our purposes.

This seems like a case where push notification would be used but what can we use with ASP.NET? HTML5 is out of the question although we've watched some push demos with web sockets.

  1. Is there a push technology we can use for ASP.NET?
  2. If not, or if it's a better solution, should we poll the database with jQuery / AJAX? Any suggestions for samples we should look at?


Using HTTP you can only send responses to client queries, so pushing content without web sockets is not possible.
The most common solutions are

  • polling the server for changes and updating the table if there are any
  • updating the page on the client often and having the server generate the page if there are new data.

The latter method is the closest to pushing content, as the client do not retrieve data, but if you want to manipulate the data client-side it will be better to retrieve only the data.
A bonus in the latter is that the server handles data and turns it into a plain file, that the server can easily serve to many clients instead of creating the page every time it's opened.


Polling via ajax is the best solution here.

Since you are using ASP.NET, some of the built in ajax controls can make this pretty simple:

http://ajax.net-tutorials.com/controls/timer-control/

If you want to make a better job of this, you might consider creating a web service and using raw JavaScript or the JQuery framework to handle the ajax request / update. I say this because ASP.NET ajax sends the full page view state back to the server, which is inefficient and usually unnecessary.


"Comet" is the technology you're looking for. It's basically a handful of techniques people have come up with to do the sort of thing you're asking for. The simplest of these techniques involve causing the browser to make constant requests to the server for any updates it should know about. The most versatile (but complex) technique involves clever use of an embedded <script> tag which references a dynamic script resource.


You can use an ASP.NET Timer control coupled with an UpdatePanel to periodically check for new data and then refresh the UpdatePanel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜