views:

76

answers:

2

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 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.

+1  A: 

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)

kwah
That is my problem exactly. I was not able to see any documentation that makes js fire the events. =(
Jronny
Edited my answer to include a bit of extra information about using jQuery to fire the onChange() event. You'll need to do some testing / checking to find out if it is this event that AdoNetDataContext listens and reacts to, though.
kwah
jquery has no problem with this. It's adonetdatacontext which has no documentation (or, idk, maybe no capability). That trigger does nothing that could tell adonetdatacontext what happened.
Jronny
Well the high level answer to the steps you should take is to find out what events AdoNetDataContext listens to, and then find out whether jQuery is firing these events. This will tell you where the problem lies and from what you have told me / the assumptions I've made about AdoNetDataContext (as I stated in my answer, I'm not familiar with it), I am not sure that there can be any other failure points.
kwah
Are you familiar with Firebug? I suggest using this to observe which events are fired / acted upon when a) editing manually and b) editing using jQuery then act upon rectifying the differences.
kwah
1.) jQuery has no problem with the event, it's just that I found no api for adonetdatacontext which listens to any event via js. 2.) I've been using firebug for more than a year now, and because the js source code for adonetdatacontext is so complex, I cannot just set any breakpoint on the code. And it would take longer if there was no event api documented.
Jronny
I realise that this might just be frustrating issues somewhat but using firebug I was unable to get javascript/jQuery to fire the onChange event by changing the .value so I still suspect that it is a problem with events not being triggered and *NOT* with AdoNetDataContext.
kwah
I initially used this method [ blog.orbeon.com/2007/06/firebug-watching-events_03.html ] to listen for events and also $("msgb").setAttribute('onChange','console.info("foo")').textContent = 'foobar3'; to test for when the change events get triggered.Only manual editing fired the event. I was unable to get $().change() to work.
kwah
+2  A: 

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

ZXX
just as when I thought there's a solution to my problem... *sigh* =(
Jronny