更新面板刷新后运行 Javascript

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7844061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 01:31:34  来源:igfitidea点击:

Running Javascript after update panel refresh

c#javascriptasp.net

提问by Bill Daugherty

How do I load a javascript command (like an onload or onclick or something) after the update panel was just refreshed.

如何在更新面板刚刚刷新后加载 javascript 命令(如 onload 或 onclick 或其他内容)。

回答by

Embed these lines on your javascript tag

将这些行嵌入到您的 javascript 标签中

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()">

回答by deostroll

ScriptManager.RegisterClientScriptBlock(upPanel, upPanel.GetType(), "alert('hello world')", true);

You must call this on partial postback.

您必须在部分回发时调用它。

回答by Candide

You could use ScriptManager. I'd think ScriptManager.RegisterClientScriptBlockshould be useful. You can then execute JS after the page load. Other options include JQuery.live.

您可以使用ScriptManager。我认为ScriptManager.RegisterClientScriptBlock应该很有用。然后可以在页面加载后执行 JS。其他选项包括JQuery.live