Introduction to ASP. NET AJAX

Source: Internet
Author: User

Officially give the syntax for calling the background class:

Class Name. method name parameter 1, parameter 2 ,......, Parameter n, callback function)

That is to say, there are two differences in calling: one is that variables do not need to be used to receive the return value, and the other is to add a parameter after all parameters: callback function. For example, there is a class method called in the background:

 
 
  1. var1 = Class1.Method1(Para1,Para2); 

Switch to the front-end JS call as follows:

 
 
  1. Class1.Method1(Para1,Para2,CallBackFunction); 

Where can I obtain the returned value? The answer is in the callback function. The prototype of the callback function is: callback function name return value ). Of course, the name of the variable storing the returned value is randomly obtained by the developer, and then the variable can be used in the callback function. For example, write a function in the above program:

 
 
  1. function CallBackFunction(result){} 

In this function, the result contains the returned values of Class1.Method1 (Para1, Para2, CallBackFunction.

Why don't we directly call methods in the class, instead of going through WebService?

As mentioned above, ASP. net ajax allows us to directly call methods in the background class, but we do not advocate this, but advocate the transition through WebService. The reasons are as follows:

1. To enable a class to be called by JS, you also need to make some modifications in it, such as adding some Attribute), which will cause a "pollution" to these classes ".

2. As we know, the ASP. net ajax framework also needs to get the return value from the callback function, rather than directly obtaining it. Consider the following: if a JS segment needs to call three background methods to complete an operation, you need to write three callback functions. That is, you must go through "call the first method-call the second method in the first callback function-call the third method in the Second callback function-get the return value in the third callback function ".

This process is very troublesome. After using WebService, We can encapsulate these three methods into a WebService method, because WebService supports the traditional call method "variable = Class Name. method name. In this way, through the WebService transition, only one callback function is required in JS.

3. In terms of its own features, WebService is more suitable for ASP. net ajax background methods than common classes.

  1. Introduction to ASP. net mvc Framework
  2. Introduction to MvcAjaxPanel in ASP. NET MVC
  3. ASP. net mvc Framework to save UpdatePanel
  4. Use ASP. net mvc source code to find a solution
  5. ActionInvoker of ASP. net mvc Framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.