如何让客户端脚本在 ASP.NET 回发上执行? (来自更新面板)

发布于 2024-09-09 06:57:09 字数 516 浏览 2 评论 0原文

基本上我想将一些 javascript 发送回客户端并从 UpdatePanel 内的回发执行。此外,这是在可重用的 WebControl 内部。

我已经尝试过 this.Page.ClientScript.RegisterStartupScriptthis.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 技术交流群。

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

发布评论

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

评论(1

半透明的墙 2024-09-16 06:57:09

如果我理解正确,您会查找 endRequest 事件 - 以避免加载图像。使用此代码,您可以在 javascript 端获取面板更新事件。

var prm = Sys.WebForms.PageRequestManager.getInstance();    
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);

function InitializeRequest(sender, args) {      
}

function EndRequest(sender, args) {
}

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