Proper way to include scripts in an asp.net page

后端 未结 3 1058
暗喜
暗喜 2021-01-11 18:11

I\'ve got an ASP.NET application that uses a mixture of ASP.NET AJAX (Including UpdatePanel) and jQuery written by several developers of differing backgrounds.

Some

3条回答
  •  梦毁少年i
    2021-01-11 19:03

    An is the declarative equivalent of calling ScriptManager.RegisterScriptBlock(), much like any other asp.net control declaration is similar to doing a programmatic Controls.Add().

    That being said, there really isn't a "preferred way". If you're building distributable web controls, then you'll want to be calling the various .RegisterScript...() methods from your control's setup routines, rather than relying on the user having to add markup.

    If you just want to include scripts in a website, it's probably more convenient to use the markup method.

    If you're adding scripts during Ajax calls, then you would want to use the ScriptManager to do it. If you're adding scripts on regular postbacks, then you would want to use the ClientScriptManager to do it.

    So... it's tough to enumerate the pros and cons. In your case, if you're not building redistributable code, then the most obvious and straightforward way is to include script references via markup, because it tends to be more visible. But I'm not sure you'll be able to consolidate every occurrence to one method, because all the methods exist for a reason, and you may need to use more than one.

提交回复
热议问题