Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh client browser when adding new line in a specific table

My scenario:

After client login, my user will be redirected to the index.aspx page. Inside this page I will put one div with a gridview inside. This gridview will be showing data from one table.

My question is: How to refresh this gridview always that one record is saved on this table?

Ps.: I´ve seen a lot of examples using "server push" tecnology, comet, ajax, etc. Don´t know the best way to do that and can´t find a really simple example.

like image 987
Fabio Avatar asked Jan 21 '26 00:01

Fabio


2 Answers

When a new record is added to the table, the real challenge is communicating those changes to the client in real-time without polling in intervals or requiring some sort of 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:

    • 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:

    • WebSync Tutorials
    • PokeIn Basic Tutorial / PokeIn Advanced Tutorial

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

like image 157
James Johnson Avatar answered Jan 22 '26 13:01

James Johnson


You can use setinterval javascript method. I act as a timer and use submit form to refresh the page. other method could be asp.net ajax toolkit timer control here

like image 30
Adil Avatar answered Jan 22 '26 12:01

Adil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!