如何有一个更新面板回发后执行的JavaScript回调? [英] How to have a javascript callback executed after an update panel postback?
问题描述
我使用一个jQuery插件提示显示帮助提示,当用户将鼠标悬停在页面的某些元素。
I'm using a jQuery tip plugin to show help tips when the user hovers certain elements of the page.
我需要的网页使用CSS选择器加载后注册插件事件。
I need to register the plugin events after the page is loaded using css selectors.
问题是我使用的是ASP.NET更新面板和第一回发后,提示停止工作,因为更新面板替换页面内容,但不会重新绑定JavaScript事件。
The problem is I'm using an ASP.NET Update Panel and after the first postback, the tips stop working because the update panel replaces the page content but doesn't rebind the javascript events.
我需要一种方法更新面板刷新了其内容后执行JavaScript回调,这样我就可以重新绑定JavaScript事件有提示再次合作。
I need a way to execute a javascript callback after the Update Panel refreshes its content, so I can rebind the javascript events to have the tips working again.
有没有办法做到这一点?
Is there any way to do this?
推荐答案
而不是把你的jQuery code $(文件)。就绪内()
中,将其放在
Instead of putting your jQuery code inside of $(document).ready()
, put it inside
function pageLoad(sender, args) {
...
}
页面加载
终止后每回发,同步或异步执行。 页面加载
在ASP.NET AJAX保留函数名称就是为了这个目的。 $(文件)。就绪()
,另一方面,只执行一次,当DOM最初是准备/加载。
pageLoad
is executed after every postback, synchronous or asynchronous. pageLoad
is a reserved function name in ASP.NET AJAX that is for this purpose. $(document).ready()
on the other hand, is executed only once, when the DOM is initially ready/loaded.
参见ASP.NET AJAX客户生命周期事件,此概述
See this Overview of ASP.NET AJAX client lifecycle events
和也看看戴夫病房的伟大的职位 - <一个href=\"http://encosia.com/2009/03/25/document-ready-and-pageload-are-not-the-same/\">$(document).ready()和页面加载()是不一样的!
And also take a look at Dave Ward's great post - $(document).ready() and pageLoad() are not the same!
这篇关于如何有一个更新面板回发后执行的JavaScript回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!