How to refresh aspx page from sql server.I am using asp.net,C-Sharp with SQL Server 2008.What i mean is i have table, say Table1.If any DML operation is performed (Update,Insert etc) to Table1,then my page,say Page1.aspx should autmatically get refreshed.I can't use timer for refreshing the page.I need to trigger the refresh from database.
-
Should the page get refreshed even if the browser is closed? – Oded Apr 10 '12 at 15:15
-
@Oded:-I guess my purpose won't be solved by closing the browser – Joby Kurian Apr 10 '12 at 15:17
-
have a look at this : http://stackoverflow.com/questions/1437309/how-to-refresh-a-page-when-record-in-db-table-get-changed-in-asp-net-3-5 – Zaki Apr 10 '12 at 15:17
-
**http://www.asp.net/web-forms/tutorials/data-access/caching-data/using-sql-cache-dependencies-vb** – huMpty duMpty Apr 10 '12 at 15:18
-
1Are you trying to update the page in real-time or on the next postback? – James Johnson Apr 10 '12 at 16:00
3 Answers
Even though the server may be notified when data has changed, the real challenge is communicating those changes to the client in real-time without requiring a timer or user interaction.
You have a couple of options:
Your best bet is to use a WebSocket, which enables bidirectional communication between the client and server. This is the solution I would pick.
Here are some examples using
WebSockets
:- Building real-time web apps with WebSockets using IIS, ASP.NET and WCF
- HTML5 C# WebSockets Server and ASP.NET Client Implementation
- C# WebSocket Server
- WebSockets in ASP.NET 4.5
- WebHooks and WebSockets in ASP.NET
There are a few good libraries around too that will take care of most of the leg work. A couple to check out are WebSync and PokeIn. Both products offer decent documentation and community editions that you can download for free.Here are some tutorials to check out:
Use AJAX to poll for changes every
X
number of seconds. If changes are detected reload the page, otherwise do nothing.

- 1
- 1

- 45,496
- 8
- 73
- 110
You probably want to look into the SqlDependency object. This object will notify you of changes to a specified database query in real time. When your application receives a message from the database, you can simply refresh the page in your code-behind.

- 1,471
- 11
- 17
-
-
2The problem with this approach is that it doesn't communicate back to the client in real-time. – James Johnson Apr 10 '12 at 16:24
-
You're probably right James... once the page has loaded, it doesn't matter that the SqlDependency has been registered since the page is no longer actively executing. I'm still thinking in WPF mode. – Michael Bowersox Apr 10 '12 at 17:14
I wonder if you could adapt SignalR to send a message to the client to prompt a refresh?
This tutorial could get you started.

- 4,176
- 2
- 26
- 48