How to call a client side javascript function after a specific UpdatePanel has been loaded

后端 未结 3 577
囚心锁ツ
囚心锁ツ 2020-12-07 15:18

How is it possible to call a client side javascript method after a specific update panel has been loaded?

Sys.WebForms.PageRequestManager.ge

相关标签:
3条回答
  • 2020-12-07 15:30

    Thanks - both good answers. I went with the client side script "pageloaded" in the end. That is a fairly buried method that google did not reveal to me. For those who are interested, this code works with FireBug to give a good demo of the PageLoaded method working to find the updated panels:

    <script type="text/javascript">
            $(document).ready(function() {
                panelsLoaded = 1;
                Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoaded)
            });
    
            function PageLoaded(sender, args) {
                console.log("I have occured " + panelsLoaded++ + " times!");
    
                var panelsCreated = args.get_panelsCreated();
                for (var i = 0; i < panelsCreated.length; i++) {
                    console.log("Panels Updating: " + panelsCreated[i].id);
                }
    
                var panelsUpdated = args.get_panelsUpdated();
                for (var i = 0; i < panelsUpdated.length; i++) {
                    console.log("Panels Updating: " + panelsUpdated[i].id);
                }
            }
        </script>
    
    0 讨论(0)
  • 2020-12-07 15:32

    This may be your solution.

    In the code behind for the UpdatePanel's OnLoad event, register a startup script.

    string scriptText = "alert('Bar!');";
    
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "foo", scriptText, true);
    
    0 讨论(0)
  • 2020-12-07 15:38

    You can hook the PageRequestManager.beginRequest event and inspect the BeginRequestEventArgs.postBackElement property.

    Note that it doesn't really give you the UpdatePanel, but the control inside of the UpdatePanel. That should be good enough, though.

    Edit: Even better, the PageRequestManager.pageLoaded event gives you PageLoadedEventArgs.panelsUpdated (and panelsCreated) properties.

    0 讨论(0)
提交回复
热议问题