I have several input and option elements on my page, each (well almost) have an event attached to update some text on the page once they change. I use jQuery which is really really cool :)

I also use Microsofts Ajax framework, utilizing the UpdatePanel. The reason why I do that is that certain elements are created on the page based on some server-side logic. I don't really want to explain why I use the UpdatePanel - even if it could (it can with quite some effort) be rewritten to use only jQuery I still want that UpdatePanel.

You probably guessed it - once I have a postback on the UpdatePanel the jQuery events stops working. I actually was expecting this, since the "postback" is not really a new postback so my code in document.ready that binds the events won't be fired again. I also confirmed my suspicion by reading up on it in the jQuery help libraries.

不管怎么说,在UpdatePanel更新完DOM之后,我仍然有重新绑定控件的问题.我最好需要一个不需要添加更多的解决方案.js文件(jQuery插件)添加到页面上,但可以捕获UpdatePanel的"AfterUpdated",在这里我可以调用我的方法来重新绑定所有表单元素.

推荐答案

由于您使用的是ASP.NET AJAX,因此您将可以访问一个pageLoad事件处理程序,每当页面从UpdatePanel回发时都会调用该事件处理程序,无论它是完整的还是部分的.你只需要把这个函数放到你的页面上,不需要连接.

function pageLoad(sender, args)
{
   if (args.get_isPartialLoad())
   {
       //Specific code for partial postbacks can go in here.
   }
}

Jquery相关问答推荐

JQuery AJAX数据表保留前导零

如何在for循环期间上传文件

如何在 jquery 中切换 attr()

与其他 Javascript 框架相比,为什么 jQuery 被如此广泛地采用?

无法使用 HTML 设置未定义的 jQuery UI 自动完成的属性_renderItem

在 div 中找到第一次出现的类

如何用另一个响应替换窗口的 URL 哈希?

Javascript 仅打印 iframe 内容

如何 Select 具有特定文本的所有锚标记

JQuery通过类名获取所有元素

在 jQuery 中,我想删除 div 中的所有 HTML

纯css关闭按钮

如何使用 jQuery 以编程方式触发对链接的点击?

如何在 jQuery 中存储全局值(不一定是全局变量)?

jquery:更改URL地址而不重定向?

从附加元素获取 jQuery 对象的更简单方法

循环判断复选框并计算每个选中或未选中的复选框

自动完成将值而不是标签应用于文本框

Isotope 和 Masonry jQuery 插件之间的区别

jquery追加到列表的前面/顶部