Callback and Controls Rendering (Manual Partial Page Rendering)

Callback and Controls Rendering (Manual Partial Page Rendering)

In my previous article, I wrote about Callback and JSON-based JavaScript serialization.

Why Should I Read this Article?

Callback doesn’t cause postback and page rendering, either full nor even partial. You can communicate with the server (IIS) and your server side code runs there successfully. You could rebind your controls, such as Dropdownlist, Gridview, Listview, Datalist, Repeater, or any server-side control to which you assign data. However, the problem is when the page won’t render, its controls won’t render; if controls won’t render, changes won’t reflect. When changes won’t reflect, there won’t be anything at the front end to show on the web page.

This article is mainly about the Callback and Rendering controls, but through this tutorial you also can learn many other things, such as a brief introduction of Postback, Rendering, creating server-side controls dynamically, and creating a Datatable dynamically in memory. Binding with server-side controls means getting server-side control at the client side and setting their properties and registering a client-side event of a server-side control from/through server-side code.

First of all, I would like to brief you on some terms that I believe every web developer should be aware of.

Postback

Postback is a mechanism of communication between the client side (browser) and the server side (IIS). Through postback, all contents of the page/form(s) are sent to the server from the client for processing. After following the page life cycle, all server-side contents get rendered into client-side code and the client (browser) displays those contents. Callback is another way of communication between the server and client. Callback doesn’t follow the page life cycle that followed standard postback and doesn’t even cause Rendering.

Rendering

Rendering is the process of converting server-side code/contents into client-side code/content so the client (browser) can understand that code and display the output. The browser can understand or, you may say, decode the code of client-side languages and scripts such as HTML, DHTML, XHTML, JavaScript, Vbscript, and others.

If rendering won’t happen, the changes won’t reflect; this happens on the server at the client side. Ajax leverages partial postback automatically, whereas callback doesn’t cause it, so a programmer needs to perform that task manually.

The ASP.NET team has created a RenderControl method with each control. By using that control, you can render your control very easily.

CALLBACK

CALLBACK is a lightweight process. It uses the well-known xmlhttp object internally to call a server-side method. It doesn’t cause page postback, so it doesn’t cause page rendering. To show output at the client side, you need to make the output HTML yourself and render the controls manually.

ICALLBACKEVENTHANDLER

ICALLBACK is implemented in ASP.NET by using the ICALLBACKEVENTHANDLER interface. This interface has two methods; one of them is used to call from JavaScript (client-side code), and the other one returns results asynchronously back to the JavaScript function.

You just need to perform some action through server-side code at the server side; it needs to return results but the results could be an instance or object of any class that could be not easy for JavaScript code to handle easily. Here, I prefer JSON, which stands for JavaScript Object Notation.

More by Author

Must Read