在解除绑定UpdatePanel的ASP事件之前Ajax请求prevent内存泄漏 [英] Unbind Events in ASP UpdatePanel BEFORE Ajax Request to prevent Memory Leak

查看:176
本文介绍了在解除绑定UpdatePanel的ASP事件之前Ajax请求prevent内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个常见的​​问题,ASP的UpdatePanel内jQuery的小部件需要一个Ajax请求后重新初始化,但我的问题是,事件是不更换UpdatePanel内的HTML之前绑定。 jQuery的照顾这个问题给你当你打电话的.html(...)或一个.remove(),但在UpdatePanel不使用jQuery的。

It's a common problem that jQuery widgets inside ASP UpdatePanels need to reinitialized after an ajax request, however my issue is that events are not unbound prior to replacing the HTML inside the UpdatePanel. jQuery takes care of this problem for you whenever you call .html("...") or .remove(), but the UpdatePanel doesn't utilize jQuery.

我有弹出元素(在UpdatePanel内),这就需要在用户点击其中的外面,所以我做了一个jQuery的特殊事件检测何时发生这种情况,不过拆卸功能是从来没有Ajax请求后调用被隐藏。因此,随着时间的推移有上的元素越来越多的事件处理程序中不再附加到文档。

I have popup elements (inside of the UpdatePanel), which need to be hidden when the user clicks outside of them so I made a jQuery Special Event for detecting when this happens however the Teardown function is never called after the Ajax request. So over time there are more and more event handlers on elements which are no longer attached to the document.

我可以有我的小部件的初始化函数(它获取每个Ajax请求后跑了),检查分离的元素和解除他们的活动,但恐怕会导致其他问题的道路。

I could have my widget initialization function (which gets ran after every Ajax request), check for detached elements and unbind their events but I'm afraid that could cause other issues down the road.

推荐答案

虽然我解决了这个问题,我的previous答案,本文对code项目可能是给其他人有类似问题的帮助:
HTTP://www.$c$cproject.com /文章/ 34348 / jQuery的-内存泄漏在UpdatePanel中

Although I solved the issue with my previous answer, this article on Code Project may be of help of to others with similar issues: http://www.codeproject.com/Articles/34348/jQuery-Memory-Leak-in-UpdatePanel

首先,它建议使用 Sys.Application.add_load 这是在页面加载和ASP Ajax请求后,尽管它不会解决你的内存泄漏跑了。

First it suggests using Sys.Application.add_load which is ran on pageload and after ASP Ajax requests although it won't solve your memory leak.

其次,要小心你如何绑定通过JavaScript倒闭事件。然而,这可能无法完全解决UpdatePanel的具体问题。

Secondly, be careful with how you bind events via javascript closures. However this may not completely solve the the UpdatePanel specific issues.

第三,你可以添加处理功能HTML ASP时,用破坏Ajax请求的HTML被执行的元素。该处置函数应该解除绑定的事件处理程序的任何删除对元素的任何其他引用。这应该是在棺材ASP UpdatePanel的内存泄漏盖棺定论。

Third, you can add a dispose function to HTML elements which is executed when ASP destroys the HTML with the ajax request. The dispose function should unbind event handlers any remove any other references to the element. This should be the final nail in the coffin for ASP UpdatePanel memory leaks.

这篇关于在解除绑定UpdatePanel的ASP事件之前Ajax请求prevent内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆