Asp.net页面生命周期错误, [英] Asp.net page life cycle error,

查看:69
本文介绍了Asp.net页面生命周期错误,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何在asp.net的部分回发的更新"面板中调用javascript fn

更新面板正在进行部分回发,并且我有一个Timer_Tick方法,在其中调用该方法进行数据绑定和updatepanel onLoad来进行图形的某些计算.我使用Javascript绘制图形

update panel is doing partial post back, and I have a Timer_Tick method where I call the method to do data binding and updatepanel onLoad for some calculation for graph. I use a Javascript to draw the graph

 window.onload = function () {
      r.init();
    }; 

因此,在页面加载时将显示该图,当更新面板在4秒钟后更新时,不会调用r.init.我尝试了很多事情.该图消失.有人可以给我一个关于页面部分回发后如何执行JavaScript的示例.

SO the graph is displayed when the page loads, when the update panel updates after 4 seconds the r.init is not called. I tried many things. the graph disappears. can someone give me a example of how to execute the JavaScript after the page partial postback.

<asp:UpdatePanel runat="server" ID="Holder" OnLoad="Graphstats" UpdateMode="Always" ChildrenAsTriggers="True">
                <ContentTemplate>
...
                   <asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer_Tick" />
            </ContentTemplate>
        </asp:UpdatePanel>

推荐答案

您的站点具有一个asp:ScriptManager.该控件与Javascript中的PageRequestManager对象进行通信.您可以使用代码插入updatepanels的所有通信中.

Your site has an asp:ScriptManager. This control communicates with the PageRequestManager object in Javascript. You can hook into all communications of updatepanels with your code.

  • beginRequest
  • endRequest
  • initializeRequest
  • pageLoaded
  • pageLoading

我认为pageLoaded是最适合您的方法.

I think pageLoaded is the best for your approach.

<script type="text/javascript">
window.onload = function () {
  // PageLoad for sync only
  r.init();
}; 

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function(sender, args) {
  // PageLoad for sync and async!
  r.init();
});
</script>

您可以扩展代码以检查导致该帖子的控件,以便优化您的代码.

You can extend the code to check which control caused the post in order to optimize your code.

MSDN: Sys.WebForms.PageRequestManager

这篇关于Asp.net页面生命周期错误,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆