I am a little confused about the benefits or conc using scriptmanager with ajax calls or use JQuery to direct call webmethods.
Can some one give me some hints about this issue? when to use which? there is any different while dealing with JSON?
I am a little confused about the benefits or conc using scriptmanager with ajax calls or use JQuery to direct call webmethods.
Can some one give me some hints about this issue? when to use which? there is any different while dealing with JSON?
I think the MSDN ScriptManager control page does a good job of summing up the features -
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.
Essentially the ScriptManager does what it says, manages your scripts without too much concern on your part with writing the JavaScript "glue" to do it yourself.
Of course, there is (some might say significant) overhead to including the ScriptManager control, not least the amount of additional requests made for script resources and the size of the generated proxy classes to call web services and page methods. This may not be so important when developing an intranet application where bandwidth and network speed are likely to be less of a problem compared to developing an application for the internet, but it's important to be aware of, nonetheless.
If you're comfortable with a JavaScript library that is capable of replacing all features of the ScriptManager whilst also being lighter in weight and as fast to get things done, then that sounds like a good case to not use the ScriptManager.
In terms of dealing with JSON, both jQuery and the ScriptManager handle it fine. IIRC, JSON is the default data type for Page Methods and Web Services in .NET (although something is reminding me that this was not always the case).
WRT Ajax calls? Very little. Very very little. There are a few possible benefits to the ASP.NET AJAX framework over jQuery:
Syntax. The framework allows you to make your webservice calls look like you really are calling some local method and passing it parameters:
MyNamespace.MyWebservice.MyMethod('arg1value', 'arg2value', onResult);
Notice how the framework version knows the order of the parameters to the Web Service Method.
jQuery's .ajax
requires the plumbing to be setup to call a ASP.NET AJAX Web Service method. It is minimal and blogged about fairly. well:
$.ajax({
type: "GET",
url: "MyWebservice.asmx/MyMethod",
data: '{"arg1":"arg1value","arg2":"arg2value"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
onResult(data.d) // ASP.NET returns payload in `".d"` property
}
});
JSON serialization for passing args to the web service: the ASP.NET Ajax Framework has Sys.Serialization.JavaScriptSerializer.serialize
which does the work of serializing your Web Service parameters "behind the scenes". With only jQuery might have to include a 3rd library, for example json.org's JSON.stringify
1. This is so negligable as to be moot.
Hardcoding GET and POST request types. Since the framework generates a JavaScript client proxy from the WebService class definition for you, you generally don't know (or care) what the HTTP request method is in the client. You just set it in the ScriptMethod
attribute on your Web Service class and call it from the client. With jQuery you must know it in order to pass it to .ajax
as the type
option.
As for benefits wrt non-Ajax stuff, @Russ Cam summed them up already for ya.