如何使用更新面板调用 javascript 函数

发布于 2024-10-04 16:27:42 字数 295 浏览 0 评论 0原文

我的解决方案中有一个更新面板。更新面板包含三列(div - s),其中包含动态添加的内容。我决定如果每个树列都具有相同的高度会更好,并且还决定使用 javascript 函数。问题是:如何在更改列高的事件上调用 javascript 函数?

我尝试在回发事件中使用它,

    Page.ClientScript.RegisterStartupScript(this.GetType(), "check", "check()", true);   

但这不起作用......请帮助......

I have an Update panel in my solution. Update panel contains three columns(div - s) with dynamically added content. I desided that it would be better if each of tree columns would have the same height, and also desided to use javascript function. The problem is: how to call javascript function on event that changes columns height?

I tried to use this on postback event

    Page.ClientScript.RegisterStartupScript(this.GetType(), "check", "check()", true);   

but this don't works... please help....

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

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

发布评论

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

评论(2

风苍溪 2024-10-11 16:27:42

像这样使用,这会有帮助。

System.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(),       "resize", "resize()", true);

use like this, this will help.

System.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(),       "resize", "resize()", true);
2024-10-11 16:27:42

最简单的方法是在 JavaScript 代码中使用 MSAjax pageLoad 事件:

 <script> 
   ///<summary>
   ///  This will fire on initial page load, 
   ///  and all subsequent partial page updates made 
   ///  by any update panel on the page
   ///</summary>
   function pageLoad(){ // Write your js code here to adjust height of the columns.  }  
 </script>

我已经使用过它很多次了,它的工作原理就像魅力一样。最重要的是不要将它与 document.ready 函数混淆(该函数仅在页面文档对象模型 (DOM) 准备好执行 JavaScript 代码后执行一次),但 pageLoad 事件将在每次更新面板时执行刷新。

来源:更新面板 AJAX asp.net 后运行脚本

Most simple way is to use MSAjax pageLoad Event in your javascript code :

 <script> 
   ///<summary>
   ///  This will fire on initial page load, 
   ///  and all subsequent partial page updates made 
   ///  by any update panel on the page
   ///</summary>
   function pageLoad(){ // Write your js code here to adjust height of the columns.  }  
 </script>

I have used it many times, it works like charm. Most important thing is don't confuse it with document.ready function (which will be executed only once after the page Document Object Model (DOM) is ready for JavaScript code to execute),yet pageLoad Event will get executed every time the update panel refreshes.

Source: Running script after Update panel AJAX asp.net

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