2

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.

Joby Kurian
  • 3,699
  • 4
  • 30
  • 38

3 Answers3

6

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:

  1. 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:


    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:

  2. Use AJAX to poll for changes every X number of seconds. If changes are detected reload the page, otherwise do nothing.

Community
  • 1
  • 1
James Johnson
  • 45,496
  • 8
  • 73
  • 110
1

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.

Michael Bowersox
  • 1,471
  • 11
  • 17
0

I wonder if you could adapt SignalR to send a message to the client to prompt a refresh?

This tutorial could get you started.

SouthShoreAK
  • 4,176
  • 2
  • 26
  • 48