Database Search Solution
(New Version) Search Control
Free ASP.NET Controls
ASP.NET Media Player Control
Flash Video Player Control
ASP.NET Telecommute Jobs
Free IP Location Lookup
Test .Net Regular Expressions
CSS/Table/DIV Page Layouts
Article Sites Master List
.NET Windows Forms
General .NET Framework
Accepting Credit Cards
Client Side Callbacks in ASP.NET 2.0
ASP.NET 2.0 includes a new Client Callback feature that enables you to retrieve page values and populate them to an already-generated page with out reconstructing page. This makes it possible to use on a page with out going through the entire post back cycle; that means you can update your pages without completely redrawing the page.
Postback and Callback
Before we appreciate the feature of Callback, let's see how current Postback feature in a typical ASP.NET page works
In a normal Postback situation, when any page event is triggered on ASP.NET page, a HTTP post request will be sent to web server, which then processes the request with the IPostbackEventHandler and runs the request through a series of page events. These events include loading the state (ViewState), processing data, processing Postback events and finally rendering the page to be interpreted by the consuming browser.
This process completely reloads the page in the browser, which is what causes the flicker and the realignment to the top of the page.
Let's see an example to see how Callback feature works. Following page will generate Current date when end user clicks the button on the form, the callback service is initiated and current date is populated into the textbox. You can download sample Callback ASP.NET project, used in this tutorial.
Clicking the button on the page invokes the client callback capabilities of the page, and the page then makes an asynchronous request to the code behind of the same page. After getting a response from the part of the page, the client script takes the retrieved value and places it inside the text box - all without doing a page refresh.
<input id="Button1" type="button" onclick="GetDate()" value="Get Date" />
Now turn your attention to the code behind.
The page class of the web page implements the System.Web.UI.ICallbackEventHandler interface.
This interface requires you to implement a couple of methods - the RaiseCallbackEvent, and the GetCallbackResult methods, both of which work with the client script request. RaiseCallbackEvent enables you to do the work of retrieving the value from the page, but the value can be only of type string.
eventArgument As String)
The GetCallbackResult is the method that actually grabs the returned value to be used:
In addition, the Page_Load event includes the creation and placement of the client callback script manager (the function that will manage requests and responses) on the client:
cbReference As String
Now, you have a page that refreshes content without refreshing the overall page. This opens the door to a whole new area of possibilities. One possible caveat is that the callback capabilites described here use XmlHTTP and, therefore, the client browser needs to support XmlHTTP. Because of this, this .Net Framework 2.0 introduces the SupportCallBack and the SupportXmlHTTP properties.