Use of ICallbackEventHandler:
To use ICallbackEventHandler, we will need to inherit it on the page
or in a user control. The code will for this will be:
public partial class Default2 :
System.Web.UI.Page,System.Web.UI.ICallbackEventHandler
As a result of inheriting from
ICallbackEventHandler, we have to implement two functions, namely:
- public void RaiseCallbackEvent(String
eventArgument)
- public String GetCallbackResult()
As name of the above two functions indicates, the first function gets
called automatically whenever there is a CallbackEvent. After the first
function the second function i.e. GetCallbackResult gets called and
returns a string to the client
So how to raise a CallbackEvent? For this we will have to use
javascript. There will be two javascript functions:
- A function which will call RaiseCallbackEvent.
- A function which will handle the response from the server. This
function will be called automatically after GetCallbackResult()
and the string returned by GetCallbackResult will appear in JavaScript
as input to this function.