开发者

why can't the datacontext detect changes to controls binded to a dataview when these changes are done via js?

I created a javascript AdoNetDataContext and created a DataView from it. I was using textboxes on the template for the table columns. AdoNetDataContext can track changes if there were any on the textboxes corresponding to the table columns used. But my changes to the textbox are done via jquery. The thing开发者_JS百科 is, datacontext does not recognize that there were changes, thus cannot commit them.

What must be the reason behind this behavior and how can we solve this problem? Thanks a lot.


DataContext and therefore AdoNetDataContext as it's derivative use JavaScript on their own to track and report actual changes while remaining data-agnostic. They are designed to work with humans, not another code :-) If you need to send data from code you can do that straight to JSON web service - no need to fiddle with autogenned UI at all. The deal with pretty much all these ASP.NET autogenned controls is that they are meant for simple things when a company doesn't want to be bothered with doing UI at all - plug and play :-)

For Web UI which does allow and even invites modifications you'll need to switch to MVC.NET (also known as ASP.NET MVC - ppl like to play with names a lot :-)


I'm not familiar with AdoNetDataContext / ASP but it sounds like edits made using jQuery do not fire the events that it uses to detect changes in the textbox values.

Assuming that this is the case, your options are:

  1. Get jQuery to fire the correct events
  2. Get jQuery to fire AdoNetDataContext-specific functions to force recognition of the changes
  3. Get AdoNetDataContext to listen for whatever events are fired by jQuery

.
The most "correct" option is #1, IMHO.

EDIT:
1. Get jQuery to fire the corect events::

There exists a jQuery function which triggers events: http://api.jquery.com/trigger/

According to the documentation there, something like this should work (untested):

$('foo').trigger('change');

(Note: this is assuming that AdoNetDataContext is listening to the 'onChange' event. If not, you'll need to find out what it is listening to and call that function instead)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜