Sys.Application.add_load() vs. $(document).ready() vs. pageLoad()

后端 未结 4 501
春和景丽
春和景丽 2020-12-13 00:55

I have page that has some javascript that needs to run at page load. Said javascript needs to locate the client-side component of a ServerControl, which it does with $find(

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 01:24

    I believe if you add (or move) a ScriptManager control above your script block, you wouldn't need to wrap it in jQuery's $(document).ready() function. By doing this apparently Sys will be available as the ScriptManager:

    injects the bulk of that JavaScript in the exact location that the ScriptManager control is positioned at in the page. [http://encosia.com/2007/08/16/updated-your-webconfig-but-sys-is-still-undefined/]

    However, this solution may still give you heartburn as it would certainly not be obvious to any unsuspecting developer what the ScriptManager is actually providing here.

    Another method where script references are added inside the ScriptManager (see "Better Way" discussed in the linked article above) doesn't sit that well with me either as I'm not a huge fan of the whole ScriptManager approach.

提交回复
热议问题