I am writing a small asp.net WebForms app. that uses Jquery. Is there any benefit to using the ASP.Net ScriptManager control as opposed to just using the tag to import my Jquery and custom javascript cod开发者_运维百科e?
You must use a ScriptManager control on a page to enable the following Microsoft Ajax features of ASP.NET:
- Client-script functionality of the Microsoft Ajax Library, and any custom script that you want to send to the browser. For more information, see Creating Custom Client Script by Using the Microsoft Ajax Library.
- Partial-page rendering, which enables regions on the page to be independently refreshed without a postback. The ASP.NET UpdatePanel, UpdateProgress, and Timer controls require a ScriptManager control in order to support partial-page rendering.
- JavaScript proxy classes for Web services, which enable you to use client script to access Web services and specially marked methods in ASP.NET pages. It does this by exposing the Web services and page methods as strongly typed objects.
- JavaScript classes to access ASP.NET authentication, profile, and roles application services.
If you're not using Ajax, you do not need to use script manager, and gain no benefits.
Source: http://msdn.microsoft.com/en-us/library/bb398863.aspx
If you are not using ASP .Net Ajax Framework, there is no real need to use the ScriptManager
and it only ads kb's to your page.
JQuery, by no ways, depends of ScriptManager
so I would recomend to only use the script tag to import your javascript code.
Hmhmm for "normal" jQuery + JS code there are no real benefits, but see the benefits listed on MSDN, there IS a reason for the ScriptManager
:
- Register script that is compatible with partial-page updates. In order to manage dependencies between your script and the core library, any script that you register is loaded after the Microsoft Ajax Library script.
- Specify whether release or debug scripts are sent to the browser.
- Provide access to Web service methods from script by registering Web services with the ScriptManager control.
- Provide access to ASP.NET authentication, role, and profile application services from client script by registering these services with the ScriptManager control.
- Enable culture-specific display of ECMAScript (JavaScript) Date, Number, and String functions in the browser.
- Access localization resources for embedded script files or for stand-alone script files by using the ResourceUICultures property of the ScriptReference control.
- Register server controls that implement the IExtenderControl or IScriptControl interfaces with the ScriptManager control so that script required by client components and behaviors is rendered.
精彩评论