开发者

how to call a javascript fn in Update panel on Partial postback in asp.net

       <asp:UpdatePanel runat="server" ID="Holder" OnLoad="" UpdateMode="Always" ChildrenAsTriggers="True">
                <ContentTemplate>
...
                   <asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer_Tick" />
            </ContentTemplate>
        </asp:UpdatePanel开发者_如何学Go>

JS:

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

when the page loads the r.init() [to draw graph] is executed. But when the page partial post back happens the graph is not drawn again. How to fire the JS when the update panel isFinite updated


You'll want to respond to these events that the upload panel will invoke before and after a partial postback.

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(...);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(...);


Copy of: Asp.net page life cycle error,?

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

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


Add endrequest handler to ur updatepanel

Check this link : http://codethatworkedforme.blogspot.com/2011/08/having-issues-with-update-panel.html


Easiest way i found was adding this javascript in the head tag:

<head runat="server">
    <script type="text/javascript" >
            function pageLoad() {
                alert('this executes after each partial post back');
                r.init();
            }
        </script>
</head>

The scriptmanager recognizes the pageLoad function and calls it after each partial post back

Source: http://encosia.com/document-ready-and-pageload-are-not-the-same/ (Section: Sometimes, pageLoad() is exactly what you want)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜