开发者

Registering a script at the end of the page using RegisterClientScriptBlock to avoid sys undefined error

开发者 https://www.devze.com 2023-04-12 03:43 出处:网络
I need to call the following programatically to set something up when a modal popup is shown. Sys.Application.add_load(modalS开发者_运维问答etup);

I need to call the following programatically to set something up when a modal popup is shown.

Sys.Application.add_load(modalS开发者_运维问答etup);

Something along the lines.

<script type='text/javascript'>
            Sys.Application.add_load(modalSetup);
            function modalSetup() {
                var modalPopup = $find("PopupBehaviorId");
                if (modalPopup != null) {
                    modalPopup.add_shown(SetFocusOnControl);
                }
            }

            function SetFocusOnControl() {
                alert('test');
            }
        </script>

Now the problem is that I have a script manager on the master page.

If I put this script manually (not programatically) below the script manager in the master page, it will work correctly.

But when I'm adding this programatically in the user control for modal popup (which I need to) using either ScriptManager.RegisterClientScriptBlock or Page.ClientScript.RegisterClientScriptBlock, it throws the famous sys is undefined error.

I know this is happening because this programatic injection puts it into the Head section before the ScriptManager line is executed.

How can I get around this. Is it possible to say insert this script at the end of the page and not at the top?


You can use ScriptManager's RegisterStartupScript method.

0

精彩评论

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

关注公众号