asp.net 更新面板之外的 jQuery

发布于 2024-09-10 20:52:15 字数 249 浏览 2 评论 0原文

我有一个正在使用和更新面板的 asp.net 页面,并且通过 {script src=abc.js} 标记包含一些 javascript。我尝试使用 $(document).ready 和 $(window).load 加载我的 javascript。两者都在初始加载时触发,但在更新面板回发时无法触发。

有什么我可以连接客户端的东西,无论更新面板如何,都会触发?我知道我可以在服务器端注入脚本,但理想情况下我希望在所有客户端都执行此操作,并在第一次时连接所需的内容。

I have an asp.net page that is using and update panel and am including some javascript via a {script src=abc.js} tag. I have tried loading my javascript using both $(document).ready and $(window).load. Both fire on the initial load but fail to fire on an update panel postback.

Is there anything I can wire up client side that would fire regardless of the update panel? I know I can inject script server side but I ideally want to do this all client side and wire up what ever is needed the first time around.

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

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

发布评论

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

评论(2

疯狂的代价 2024-09-17 20:52:16

如果您希望注册一些代码以便即使在 UpdatePanel 回发时也始终运行,则需要注册要在更新发生时调用的函数。您可以通过执行以下操作来注册要运行的 javascript 函数:

// Javascript
function InitializeScripts()
{
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(YourJavascriptFunctionYouWantToRun);
}

当 UpdatePanel 刷新时,PageRequestManager 将调用您的 javascript 函数。

过去,当 UpdatePanel 由于计时器触发刷新时,我曾使用此方法触发触发器。刷新完成后,脚本将自动运行以根据显示的数据更新其他控件。

有关详细信息,请参阅这篇 MSDN 文章

If you want to register some code to always run even on an UpdatePanel postback, you will need to register your function to be called when an update occurs. You can register a javascript function to run by doing the following:

// Javascript
function InitializeScripts()
{
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(YourJavascriptFunctionYouWantToRun);
}

The PageRequestManager will call your javascript function when the UpdatePanel refreshes.

I have used this in the past to cause a trigger when an UpdatePanel fired a refresh due to a timer. When the refresh completed, the scripts would automatically run to update other controls based on the data that was displayed.

See this MSDN article for more information.

生生漫 2024-09-17 20:52:16

将这些行嵌入您的 javascript 标签

function foo()
{
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}
function endRequestHandler(sender, args)
{
    // Do your stuff
    alert('Update Panel routine is now complete');
}

然后,将其放在您的 body 标签上

<body onload="foo()">

Embed these lines on your javascript tag

function foo()
{
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}
function endRequestHandler(sender, args)
{
    // Do your stuff
    alert('Update Panel routine is now complete');
}

Then, put this on you body tag

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