你如何获得客户端脚本上的ASP.NET回发执行? (来自一个UpdatePanel) [英] How do you get client-side script to execute on an ASP.NET postback? (from an UpdatePanel)
问题描述
基本上我想获得一些JavaScript被发送回客户端,并从UpdatePanel内回发执行。此外,这是一个可重用的WebControl里面。
Basically I want to get some javascript to be sent back to the client and executed from a postback inside an UpdatePanel. Furthermore this is inside of a reusable WebControl.
我试过 this.Page.ClientScript.RegisterStartupScript
和 this.Page.ClientScript.RegisterClientScriptBlock
,但萤火表明这些脚本没有在回发的响应发送回去。
I've tried this.Page.ClientScript.RegisterStartupScript
and this.Page.ClientScript.RegisterClientScriptBlock
but Firebug shows that those scripts aren't sent back in the postback's response.
我也试过直上写了<脚本>
在控件的主要DIV中标记渲染
方法,它发送回,但不执行。
I also tried straight up writing a <script>
tag inside the control's main div in the Render
method, which does get sent back but isn't executed.
我有一个哈克解决方案的工作,但最好找一个清洁的解决方案。该黑客是一个1x1像素 IMG
与宽度/高度设置为0,并使用了一个的onload
事件添加到执行脚本和作品,但好像必须有这样做一个更清洁的方式。
I got a hacky solution working, but ideally looking for a cleaner solution. The hack is to add a 1x1 pixel img
with width/height set to 0 and use that for an onload
event to execute the script and that works, but it seems like there has to be a cleaner way to do this.
推荐答案
如果我理解正确,你去找endRequest事件 - 以避免图像的onload事件。有了这个code你在JavaScript端的面板更新的事件。
If I understand correct you look for the endRequest event - to avoid the onload of your image. With this code you get the event of your panel update on javascript side.
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
function InitializeRequest(sender, args) {
}
function EndRequest(sender, args) {
}
这篇关于你如何获得客户端脚本上的ASP.NET回发执行? (来自一个UpdatePanel)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!