Callback and Controls Rendering (Manual Partial Page Rendering)
<script language="javascript" type="text/javascript">
//Runs when GetCallbackResult() executes and return result through
//arg param
function ReceiveServerData(arg, context)
{
//split command and contents (rendered data)
var cmd_content = arg.split(',');
//check command
if (cmd_content[0] == 'LoadSubCategory')
{
//set rendered contents to sub category div to show
//subcategories according to categories
document.getElementById('ddlSubcategories').innerHTML =
cmd_content[1];
}
else
{
//set rendered contents to products div to show products
//according to categories and sub categories
document.getElementById('grvProducts').innerHTML =
cmd_content[1];
}
}
//invoke by categories/subcategories dropdownlist to communicate
//with server for processing
function CallSrv(ddl)
{
//check command and determine either this method invoked by
//Categories Dropdownlist or by Subcategories Dropdownlist
if (ddl.id == 'ddlCategories')
{
if(ddl.value != 'Select')
{
//Set command and value to load data accordingly and call
//server side method RaiseCallbackEvent
CallServer('LoadSubCategory' + ',' + ddl.value, '');
}
}
else
//Set command and value to load data accordingly and call
//server side method RaiseCallbackEvent
CallServer('LoadProducts' + ',' + ddl.value, '');
}
}
</script>
That's it. These are the steps you need to use to call and get results from server-side code by using ICALLBACK. Asynchronous output would occur within a millisecond and without Postback.
Conclusion
Callback is a lightweight technique used to call server-side methods asynchronously from JavaScript without any postback and reloading/rendering of unnecessary parts of the page or unnecessary code. So, you can use that when you need to perform any operation at the back end—such as update records in a database. You don't need to send all the content of pages in a request and make that object heavyweight, which could cause slow performance.
About the Author
.Net Evangelist
http://weblogs.asp.net/MuhammadAdnan
http://realfantasy.wordpress.com
http://interviewquestion.wordpress.com
IT Offers
More for Developers
Top Authors
- Voted: 13 times.
- Voted: 11 times.
- Voted: 11 times.
- Voted: 8 times.
- Voted: 8 times.
- Paul Kimmel 214 articles
- Zafir Anjum 120 articles
- 15Seconds.com 99 articles
- Tom Archer - MSFT 83 articles
- Jeffrey Juday 82 articles


All