Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebForm_DoCallback definition

Is there a simple explanation on MSDN of WebForm_DoCallback function?

All I can find is this article http://msdn.microsoft.com/en-us/magazine/cc163878.aspx which does include implementation of WebForm_DoCallback but doesn't do a good job explaining parameters themselves.

function WebForm_DoCallback(eventTarget, eventArgument, 
eventCallback, context, errorCallback) 

Like what exactly does it expect as an 'eventTarget'? What is 'context'? Etc...

like image 228
dev.e.loper Avatar asked Jun 04 '10 19:06

dev.e.loper


2 Answers

WebForm_DoCallback appears to be the client-side counterpart to GetCallbackEventReference. It's generated with the same arguments, which are as follows:

target: The name of a server Control that handles the client callback. The control must implement the ICallbackEventHandler interface and provide a RaiseCallbackEvent method.

argument: An argument passed from the client script to the server RaiseCallbackEvent method.

clientCallback: The name of the client event handler that receives the result of the successful server event.

context: Client script that is evaluated on the client prior to initiating the callback. The result of the script is passed back to the client event handler.

clientErrorCallback: The name of the client event handler that receives the result when an error occurs in the server event handler.

useAsync: true to perform the callback asynchronously; false to perform the callback synchronously.

clientCallback and clientErrorCallback are client-side (usually javascript) functions with arguments in the form:

function clientCallback(returnmessage, context) {}

Where returnmessage is the response from the server (or error) and context is the same as the context passed in previously.

References:

MSDN: ClientScriptManager.GetCallbackEventReference Method

MSDN Magazine: Implications of Script Callbacks in ASP.NET

ESRI Developer Network: Page Postbacks and Client Callbacks

like image 81
Stu Pegg Avatar answered Dec 14 '22 07:12

Stu Pegg


we can see something like this--

WebForm_DoCallback('__Page',parameter,callBack,context,null,false);

in the page resource file. it seems the 'parameter' is a value type(string), while the context is a ref type. anyway the "context" is rarely used. the "Parameter" could only be a string, so you may need combine several values into it, and then separate it on the server. while the data is transmitted to the server end, the relative class(as a subclass of interface 'ICallbackEventHandler') instant will be created, and the handler method will be called:

public void RaiseCallbackEvent(string eventArgument)
{
   //deal with the eventArgument( the "parameter")        
}

after that another method goes on and return a string back in the response..

public string GetCallbackResult()
{
    //return command;
}

finally the async process raises the callback function( "callBack" in this case),which should has 2 input params:

function callBack(returnedStuff, context) {......}

and that's how it works however I don't know where the javascript function "WebForm_DoCallback" is defined, so it may not work on the non-windows computers.

like image 42
Heroius Avatar answered Dec 14 '22 07:12

Heroius