当通过 js 完成这些更改时,为什么数据上下文无法检测到绑定到数据视图的控件的更改?

发布于 2024-09-14 20:05:33 字数 219 浏览 0 评论 0原文

我创建了一个 javascript AdoNetDataContext 并从中创建了一个 DataView。我在模板上使用文本框作为表列。如果文本框中有与所使用的表列相对应的任何更改,AdoNetDataContext 可以跟踪更改。但我对文本框的更改是通过 jquery 完成的。问题是,datacontext 无法识别发生了更改,因此无法提交它们。

这种行为背后的原因是什么?我们如何解决这个问题?多谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月下客 2024-09-21 20:05:33

DataContext 以及 AdoNetDataContext 作为其衍生品,单独使用 JavaScript 来跟踪和报告实际更改,同时保持与数据无关。它们被设计为与人类合作,而不是与其他代码合作:-) 如果您需要从代码发送数据,您可以直接将其发送到 JSON Web 服务 - 根本不需要摆弄自动生成的 UI。几乎所有这些 ASP.NET 自动生成的控件的处理方式是,当公司根本不想为 UI 做任何事情时,它们就意味着简单的事情 - 即插即用:-)

对于 Web UI 来说,它确实允许,甚至需要进行修改才能切换到 MVC.NET(也称为 ASP.NET MVC - 人们非常喜欢玩名字:-)

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

旧情勿念 2024-09-21 20:05:33

我不熟悉 AdoNetDataContext / ASP,但听起来使用 jQuery 进行的编辑不会触发它用来检测文本框值更改的事件。

假设情况如此,您的选择是:

  1. 获取 jQuery 来触发正确的事件
  2. 获取 jQuery 来触发 AdoNetDataContext 特定的函数,以强制识别更改
  3. 获取 AdoNetDataContext 来侦听 jQuery 触发的任何事件


最“正确”的选项是#1,恕我直言。

编辑:
1。获取 jQuery 来触发正确的事件::

存在一个触发事件的 jQuery 函数:
http://api.jquery.com/trigger/

根据那里的文档,类似这样应该可以工作(未经测试):

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

(注意:这是假设 AdoNetDataContext 正在侦听“onChange”事件。如果没有,您需要找出它正在侦听并调用该函数代替)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文