开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜