views:

92

answers:

4

I have a page in my website which view life information(like bourse info) from database What I want is : refresh a part of the page through the AJAX technics When a new row is added to one of the tables in the database.

A: 

If you want to go the Microsoft route, you might want to start by watching a few of these tutorials that'll get you started with ASP.NET AJAX: http://www.asp.net/learn/ajax

Bernhard Hofmann
+2  A: 

So to be clear: when something in the database changes, you want everyone viewing a page on your site that is displaying that data to be refreshed with the addition? This is the opposite direction of how AJAX typically works (something changes on the user's end and the application is notified).

What you could do is add code to do an AJAX postback every x seconds (30 seconds let's say) with an AJAX Timer. That way only that part of the page is updated (AJAX style) and the user only has a lag of 30 seconds between data update and display. Here is an example of what I mean.

colithium
Yes, what the OP asked for cannot be done (the server does not know the browsers viewing that page, so it cannot ask them to refresh). This accomplishes pretty much the same thing, and the server can control how often you want to refresh the page. +1
Marcel Popescu
A: 

The technique you should employ is "Polling"

You cannot have notifications from server to client in this situation, so you need to keep polling to server at every X seconds, asking the server "Do you have any new Data ?"

Let there be 2 AJAX enabled services in your appliction.

One should be polled at every X seconds asking the DB status. This service should return true in case there's any new data inserted in the database since last poll.

If the result from first service call is true, then you should call the Second service which will return you with the Newly inserted Rows or results in XML or any other format, which you can display comforatbly on your Page.

However, you must keep track of last polling request by its datetime of request. Everytime you send a polling request, you should also pass the DateTime of your last poll so that your service can check if there's any new data added after the last poll and return true only if there's any new data inserted after last poll. The same logic should be applied to Second service as well.

Thanks.

this. __curious_geek
A: 

you can make webservice that will check from server, if there is any change happen, and update information accordingly.....

Muhammad Akhtar