Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Client-side callbacks, a feature introduced by Microsoft in ASP.NET 2.0, allow controls to execute HTTP requests using JavaScript to obtain data on the server without posting the entire page. This is certainly a cool feature to have for performing asynchronous operations on a page without posting the complete page. Let’s implement a client-side callback on the Calculate button in the web part of the RightZone in our previous example. Create a new user control called MyControl1. This user control will have the same controls as we had in the earlier user control, MyControl, except that MyControl1 will have all HTML input controls rather than server controls. This is to illustrate that the client callbacks can be done with the plain HTML controls. The following is the source of the MyControl1 user control:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyControl1.ascx.cs" Inherits="MyControl1" %>
<script type="text/javascript">
function ClientCallbackHandler(rValue)
{
document.getElementById("result").innerText = rValue;
}
</script>
<table>
<tr>
<td>Value 1 : </td>
<td><input type="text" id="txtValue1"/></td>
</tr>
<tr>
<td>Value 2 :</td>
<td><input type="text" id="txtValue2"/></td>
</tr>
<tr>
<td> </td>
<td><input type="button" id="btnCalculate" value="Calculate" onclick="AddValues(document.getElementById('txtValue1').value+'|'+ document.getElementById('txtValue2').value)" />
<span id="result"></span></td>
</tr>
</table>