First of all, I would like to briefly describe some terms of
which I believe every web developer should be aware.
Postback
A postback is a mechanism of communication between
client-side (browser) and server-side (IIS). Through a postback all contents of
page/form(s) are sent to the server from client for processing. After following
the page life cycle, all server-side contents get render into client-side code
and the client (browser) displays the content. Callback is another form of
communication between server and client. Callback doesn’t follow the page life
cycle which is followed by standard postback, and it doesn't even cause rendering.
Rendering
Rendering is the process of converting server-side
code/content into client-side code/content so the client (browser) can
understand the code and could display the output. Browsers can understand, or
you may say decode, code of client-side languages and scripts like HTML, DHTML,
XHTML, JavaScript, VbScript, etc.
If rendering doesn't happen then changes won’t be reflected
at client-side. Ajax leverages partial page postbacks automatically whereas
callback doesn't, so programmer needs to perform that task manually.
The ASP.NET team has created a RenderControl method which is
applied to the base control. By using that method we can render our controls
very easily.
Callback
Callback is a lightweight process. It uses the well known XMLHTTP
object internally to call server side methods. It doesn't cause page postback
so doesn’t cause page rendering, so if we want to show output at client side,
we need to make output html ourselves and render controls manually.
ICallbackEventHandler
ICallback is implemented in ASP.NET by using the ICallbackEventHandler
interface, which has two methods, one of them used to be called from JavaScript
(client-side code) and the other one returned results asynchronously back to
the JavaScript function.
We just need to perform some action through server-side code
at server-side and need to return results, but the results could be an instance
or object of a class which might not be easy for JavaScript code to handle, so
here we prefer JSON which stands for JavaScript Object Notation.