I m building a website where i need to update project counter whenever its updated in DB. when ever any user add a new project, the project counter should automatically update in browser, but i don’t want to send ajax request to server again and again to get count from DB and then update counter in web browser.
I want something similar “how facebook notification updated” automatically without refreshing page or sending any ajax request, i know there are using some PUSH technology but i not sure how it works.
It will be very great if someone provide some Example code to achieve this.
Thanks…
Have you considered using SignalR?
http://www.hanselman.com/blog/AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR.aspx
http://signalr.net/
Here is the sample code based on a quick POC after reading some SO replies and above articles. Hope it helps.
Add the SignalR package via NuGet
Add a UserCounter.cs with following code. Just need to inherit the class from Hub base class.
Add a Default.aspx with following code:
Add a UpdateNoOfUsers.aspx with following code:
Add an event-handler for button-click for button in UpdateNoOfUsers.aspx
Run the application after setting “Default.aspx” as the start up page
Click on the “Change number of users” link to open a new browser window
Enter a number in text-box and click on the button to see the value change in base window! Open this page in some other browser and see the same behaviour!