Mustafa Ekici
Mustafa Ekici

Reputation: 7480

Using Dependency Property for Database

In WPF we use Dependency Properties, but I wonder if it is possible to use them in web applications.
E.g. let's say I have a textbox's value "jack". That name comes from database, so when database table field gets updated and changes that name to "john", how can this effect textbox's value, so it changes to "john" too?

Upvotes: 1

Views: 234

Answers (5)

Mustafa Ekici
Mustafa Ekici

Reputation: 7480

2021 We can do it with Firebase.

Upvotes: 0

Puhek
Puhek

Reputation: 475

There is no such thing on web as data binding in wpf. DB does not implement interfaces for data changes. What you can do is use DBs stored procedures (compiled) and communicate data change on the trigger to the web instance(s). From there on, one could update view/webpage via Ajax.

This would be "push" method which is of course better solution but harder to implement.

You can also do "data pooling" on timed interval and update page accordingly which is simple to implement but really bad resource vise.

Best regards, P.

Upvotes: 1

Preet Sangha
Preet Sangha

Reputation: 65555

Good idea - but you're missing some of the major issues.

A dependency property is essentially an in memory object that various things subscribe to for changes.

To do the same for a db you need a way to communicate that change (to the application). Since these are out of process it will have to be some cross process or even cross server/network call. All of this needs to be defined and constructed by you manually.

Upvotes: 1

Wouter de Kort
Wouter de Kort

Reputation: 39898

In a Web Application, things work a little different then in WPF applications.

In a WebApp a requests come in, the server processes it and then returns a result to the clients browser. If something changes on the server, the server has no way to let the client know this until a new requests comes in and the server can return a new response.

ASP.NET has the concept of DataBinding and DataSources. You can for example configure a SqlDataSource to execute a query and bind the results to a Grid or List control. This will execute when a user loads the page.

Automatically refreshing data when something changes on the server would require the client to constantly poll the server for changes (in a async way with AJAX) to see if there are changes and then update the HTML in the browser. This is what you see happening in apps like Twitter or LinkedIn but it is a complete different concept then what you're used to in WFP apps.

Upvotes: 1

MBen
MBen

Reputation: 3996

Short answer yes you can, it doesn't matter where the data is coming from. Write a class that implements INotifyPropertyChanged which is basically called ViewModel. This class will wrap your data coming from the DB, and notifies the view when values change.

Upvotes: 0

Related Questions