Saturday, March 24, 2012

UpdatePanel and database

Hi there.

Is it possible to use UpdatePanel with SqlDependency to update a gridview or other bounded control whenever a row is added to a table? Or the update panel triggers collection only works with controls?

Thanks in advance,
P. Conde

Hey Pedro,

About a year ago I responded to two posts regarding the same kind of topic you are talking about. Currently there is not implementation inherent to ASP.NET to accomplish your scenario. I myself was also looking to accomplish what you were trying to do as well.

The only solution that I could come up with is the solution I have listed in the following links. I have recently implemented this solution in a Proof-Of-Concept (POC) kind of way. There are server technologies out there that are not .NET and support server push technology. Specifically do a search on google for "Comet" it's a phrase that was coined by one of the creators of the DojoToolkit. Also check out Meebo.com they have a great example of implementing a service with no page refreshes simply data pushing.

The only thing I left out in the posts below was that in order to get the flash client to connect you have to put a crossdomain.xml on the server in the root inetpub folder (wwwroot).

Other than that I have implemented the Windows service to listen on a specific port, and flash connects from the browser to the server and port and passes and receives XML. Then through the External Interface it can update the page. The Windows Service can listen on a SqlCommand with the SqlDependency object for changes in the current query.

You could use the SqlDependencyCache object but that would only work for when you do a postback. All it does is invalidate the cache so that the data has to be loaded from the Sql Server again. Anyhow good luck with you project.

The Solution
http://forums.asp.net/thread/1366004.aspx
SqlDepedency Question
http://forums.asp.net/thread/1336290.aspx

JoeWeb


I have set all the SqlDependency issues and I can see by debugging that it is workin when a table changes (row inserted/deleted/...). I'm using an event in a webusercontrol as a trigger for the update panel. Even if I use label or textbox controls getting some data in a sql database, the asyncpostback doesnt work... If I use a button at the updatepanel and click on it, the grid is updated...

I have seen the video "#4 | How Do I: Implement Dynamic Partial-Page Updates with ASP.NET AJAX?" and I'm following the leads in it... Shouldn't this be working?!

Anyone has solution for this?!

P. Conde


As I have previously stated this is not possible. The best possible solution would to be implementing a custom solution.

The SqlDependency object sets up an new Notification Stored Procedure along with a Service Broker to channel the request back to the client.

However in an HTTP scenario the Service Broker cannot invoke a page refresh... and therefore it is "IMPOSSIBLE" to make this a viable solution. HTTP doesn't allow there to be a server push without it being hosted on a server that has "Comet" technology. Again your best bet is to implement a custom solution.

Even though it's wrapped in Ajax it doesn't mean it keeps an open connection... it's still doing a postback when you hit that button.

Good Luck!
JoeWeb

No comments:

Post a Comment