javascript - Registering a script at the end of the page using RegisterClientScriptBlock to avoid sys undefined error - Stack Ov

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

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

Sys.Application.add_load(modalSetup);

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?

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

Sys.Application.add_load(modalSetup);

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?

Share Improve this question edited Mar 29, 2021 at 8:13 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Oct 11, 2011 at 22:27 Alex JAlex J 1,5673 gold badges26 silver badges42 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5 +100

You can use ScriptManager's RegisterStartupScript method.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745642792a4637792.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信