Analysis of ASP.net 2.0 Client callback

Source: Internet
Author: User

asp.net 2.0 Callback enables asp.net server-side controls to invoke the service-side approach without performing a complete postback process, which means that the server-side controls can support Ajax well.

Callback differs from postback in that when a request is sent to the server only ViewState and user-defined information is sent to the server side, and after the request is completed, only the user-defined results are returned, not from the render page.

The GridView control uses this technology to achieve paging and sorting without refreshing, so how does it work, and how do we add that functionality to our custom controls? This article will briefly explain how to use the ASP.net 2.0 callback to implement Ajax.

1, ICallbackEventHandler interface

asp.net server-side controls can accept client callback events by implementing the ICallbackEventHandler interface.

ICallbackEventHandler Interface declaration:

1public interface ICallbackEventHandler
2{
3 string GetCallbackResult ();
4 void RaiseCallbackEvent (string eventargument);
5}

RaiseCallbackEvent handles the client callback event, where the method parameter eventargument is provided by the client script when the callback is triggered, and the method relies on the eventargument parameter for processing.

GetCallbackResult is responsible for returning the processing result as a string to the client script. When the callback completes, the client script will update the page locally based on the resulting processing.

2, Callbackeventreference

So how to register a client script to trigger callback, what else do you need to do?

The ClientScriptManager class is used to manage client script on a Web page, providing a series of methods for registering the script and also obtaining a reference to the specified client script function. We can get a reference to the client function through the GetCallbackEventReference method of the ClientScriptManager class. When the function is invoked on the client, a client callback is initiated.

GetCallbackEventReference Method declaration:

public string GetCallbackEventReference control
,
string argument,
string clientcallback,
String context,
string clienterrorcallback,
bool Useasync
)

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.