Skip to main content

Script Callback


What is the difference between a callback and a postback?

A callback is a special postback, so a round-trip always occurs; however, unlike the classic postback, the script callback doesn't redraw the whole page. ViewState is not updated during a callback, it is for postback.

How to make a callback?

In the client side JavaScript code, if GetCallbackEventReference() method is reference, then when the JavaScript code is executed, a channel to the server is opened and an HTTP request is sent to the remote ASP.NET page.
How does the ASP.NET runtime know this HTTP request is a Callback rather than a Postback?

After the ASP.NET runtime get a HTTP request, it looks for a __CALLBACKID entry in the Request collection. If such an entry is found, the runtime concludes that a callback invocation is being made.

GetCallbackEventReference() syntax

public string GetCallbackEventReference (
string target,      
    string argument,     
string clientCallback,      
    string context,
    string clientErrorCallback,
    bool useAsync
)

there are overloads such as
ClientScriptManager.GetCallbackEventReference (Control, String, String, String)
ClientScriptManager.GetCallbackEventReference (Control, String, String, String, Boolean)

GetCallbackEventReference() Parameters

target
The name of a server Control that handles the client callback. The control must implement the ICallbackEventHandler interface and provide a RaiseCallbackEvent method (which could be the page itself).
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.

Popular posts from this blog

Remote debugging Windows azure cloud service - Worker Role

Remote debugging Windows azure cloud service - Worker Role Very recently I was working on design and development of a worker role component of cloud service. Locally debugging worker role is pretty easy. You just need to know that you need to set Cloud project as a start-up project and ready to go. Problem is when you deploy worker role to azure and trying to troubleshoot an unknown issue.  Thankfully we have remote debugging enable for cloud services – both web and worker roles. This is really handy tool to remotely debug without having to putting a lot of tracing and digging into it. However, remote debugging in worker role/web role requires few steps to be followed: Make sure you are debugging from same machine where you published Make sure to turn on Remote debugger on while you publish (This should be turned off for Production publish profiles) Make sure to Select Debug mode With all the above settings after you publish, you should be able to Atta...

Debugging code running on Remote machine

Before performing below steps, you need to make sure you have pdb files matching dll version on the remote machine.  Open below folder in your remote machine C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Remote Debugger\x64  Open that folder and launch as admin  msvsmon.exe  Select all options to allow firewall From Tools > Options  - Keep the settings to default (as shown below) and click ok.  At this point your remote debugger is all set. You need to connect from Visual Studio by entering Machine IP: Port (4022) 

Differences between Object Serialization and Deserialization?

Serialization = putting the relevant state of the object into a streamable representation. That can mean converting it to a byte stream. This does not necessarily include copying every member variable into the stream. Deserialization = restoring an object from a serial representation and ensuring the invariants of the object. Deserialization can be thought of a separate constructor for the object.