如何让客户端脚本在 ASP.NET 回发上执行? (来自更新面板)
基本上我想将一些 javascript 发送回客户端并从 UpdatePanel 内的回发执行。此外,这是在可重用的 WebControl 内部。
我已经尝试过 this.Page.ClientScript.RegisterStartupScript
和 this.Page.ClientScript.RegisterClientScriptBlock
但 Firebug 显示这些脚本不会在回发响应中发回。
我还尝试直接在 Render 中的控件的主 div 内编写
方法,该方法确实会被发送回来但不会被执行。 标记
我得到了一个可行的解决方案,但理想的是寻找一个更干净的解决方案。破解方法是添加一个宽度/高度设置为 0 的 1x1 像素 img
并将其用于 onload
事件来执行脚本并且可以工作,但似乎有必须有一种更清洁的方法来做到这一点。
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.
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.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确,您会查找 endRequest 事件 - 以避免加载图像。使用此代码,您可以在 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.