How to Implement the most basic AJAX framework

Source: Internet
Author: User

Client callback provided by Asp. Net 2.0

Asp. Net 2.0 has been released. 2.0 has many new features, and client callback is one of them. Client callback allows us to call methods on the server without sending back. It is consistent with the functions provided by AJAX, but it is not as flexible as AJAX. AJAX can customize the called methods, the callback function provided by 2.0 does not work. To use the client callback function, you must implement the System. Web. UI. IcallbackEventHandler interface.

  This interface contains two methods


// This method is fixed during client callback.

Public void RaiseCallbackEvent (String eventArgument)

// This method will be called after RaiseCallbackEvent is executed. The return value of this method will be sent back to the client.

Public string GetCallbackResult ()

Example:

. Cs:

String cbReference = Page. ClientScript. GetCallbackEventReference (

This, "arg", "ReceiveServerData", "context ");

String callbackScript;

CallbackScript = "function CallServer (arg, context)" + "{" + cbReference + "};";

Page. ClientScript. RegisterClientScriptBlock (

This. GetType (), "CallServer", callbackScript, true );

Javascript:

   AJAX Introduction


AJAX is not a new technology, but an organic combination of existing technologies, including XmlHttp and Reflect. An AJAX framework basically includes a custom HttpHandler and a piece of JavaScript code.

  AJAX Running Mechanism

In the past, when we used XmlHttp to implement a refreshing page, we used XmlHttp to request a hidden page. net) comes with HttpHandler, and in AJAX, we request a hidden page. The difference is that HttpHandler of this page is implemented by ourselves.

  Build your own AJAX:

1. First, we need to implement an Http handler (HttpHandler) to respond to client requests:

To implement a custom HttpHandler, you must implement the IHttpHandler interface.

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.