如何在更新面板回发后执行 javascript 回调? [英] How to have a javascript callback executed after an update panel postback?

查看:30
本文介绍了如何在更新面板回发后执行 javascript 回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 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 代码放在 $(document).ready() 里面,而是把它放在

Instead of putting your jQuery code inside of $(document).ready(), put it inside

function pageLoad(sender, args) { 
    ... 
}

pageLoad 在每次回发后执行,同步或异步.pageLoad 是 ASP.NET AJAX 中用于此目的的保留函数名称.$(document).ready() 另一方面,当 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 客户端生命周期事件概述

这篇关于如何在更新面板回发后执行 javascript 回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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