AJAX. NET installation and Configuration Guide

Source: Internet
Author: User

Ajax. NET installation configuration: Download and Installation

First from AJAX.. NET project website, download and decompress the AJAX file, and then follow your preferences in Visual Basic.. NET or C. NET project, and then to AJAX. dll file reference ). The only additional configuration step is to add the following code in the <system. web> element in the web. config file.

 
 
  1. < configuration>      
  2. < system.web>    
  3. < httpHandlers> 
  4. < !-- Register the ajax handler --> 
  5. < add verb="POST,GET" path="ajax/*.ashx"   
  6. type="Ajax.PageHandlerFactory, Ajax" /> 
  7. < /httpHandlers>    
  8.   ...  
  9.   ...   
  10. < /system.web> 
  11. < /configuration> 

Install and configure AJAX. NET: Make server-side functions available

To make server-side functions available in JavaScript, two things must be done. First, the function to be used must be marked with Ajax. AjaxMethodAttribute. Second, during page loading events, you must call Ajax. Utility. RegisterTypeForAjax to register classes containing these functions. It seems complicated, but don't worry. In fact, you only need to add two more lines in the code. Let's look at an example.

 
 
  1. // C # 
  2. Public ClassSample: System. Web. UI. Page
  3. {
  4. Private VoidPage_Load (ObjectSender, System. EventArgs e)
  5. {
  6. // Register the server-side functions that we are interested in. 
  7. // Class 
  8. Ajax. Utility. RegisterTypeForAjax (Typeof(Sample ));
  9. }
  10. [Ajax. AjaxMethod ()]
  11. Public StringGetMessageOfTheDay ()
  12. {
  13. Return "Experience is the mother of wisdom";
  14. }
  15. }
 
 
  1. 'Vb. NET 
  2. Public ClassSample
  3. InheritsSystem. Web. UI. Page
  4. Private SubPage_Load (sender AsObject, eAsEventArgs)
  5. Handles MyBase. Load
  6. 'Register the server-side functions that we are interested in 
  7. 'Class 
  8. Ajax. Utility. RegisterTypeForAjax (GetType(Sample ))
  9. End Sub 
  10. <Ajax. AjaxMethod ()> _
  11. Public FunctionGetMessageOfTheDay ()As String 
  12. Return "Experience is the mother of wisdom" 
  13. End Function 
  14. End Class 

The above example first tells Ajax. NET to find a friendly Ajax method in the Sample class. It is exactly the same class as the actual page, but it can be any. NET class, or multiple classes can be registered. Ajax. NET then browses the specified class to find all the methods marked with AjaxMethodAttribute. The Sample class has a GetMessageOfTheDay.

AJAX. NET installation configuration: use functions and classes in JavaScript

After that, the only thing you have to do is to use it in JavaScript. Ajax. NET automatically creates a JavaScript variable with the same name as the registered class. In this example, the JavaScript variable is Sample. It provides a function with the same name as AjaxMethod, and GetMessageOfTheDay in this example ). As shown below.

 
 
  1. < script language="javascript"> 
  2. Sample.GetMessageOfTheDay(GetMessageOfTheDay_CallBack);  
  3. function GetMessageOfTheDay_CallBack(response)  
  4.  {  
  5. alert(response.value);  
  6.  }  
  7. < /script> 

In addition to the JavaScript callback function, JavaScript GetMessageOfTheDay also needs to have the same parameters as the corresponding part of the server. In this case, there is no parameter) to execute and pass the response when the callback is complete. Here, we can see the asynchronous feature of AJAX at work, because the call to GetMessageOfTheDay does not impede the execution of other JavaScript code, nor does it prevent the user from continuing operations on the page. When processing on the server side, Ajax. NET calls the specified callback function GetMessageOfTheDay_CallBack and sends a response composed of the return values on the server side.

The ing between server-side code and JavaScript code may be messy. Figure 1 briefly shows the server-side code and JavaScript code, and the ing between them.

Figure 1: ing between server-side code and JavaScript code

The preceding section briefly introduces the installation and configuration of AJAX. NET.

  1. Ajax. Net Quick Start
  2. Download ASP. net ajax Software
  3. The father of ASP. NET is strongly recommended: ASP. NET AJAX
  4. Analysis on the AutoComplete control of Asp.net Ajax Control
  5. Installation and simple configuration of ASP. NET AJAX

Related Article

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.