1. First, commit icallbackeventhandler
2. In page_load
Clientscriptmanager scriptmanager = This. Page. clientscript;
String eventref = scriptmanager. getcallbackeventreference (this, "argval", "oncallcomplete", "ctxval", "onerroccurs", true );
3. Server:
/// <Summary>
/// Accept the volume of the customer's terminal for Calculation
/// </Summary>
/// <Param name = "eventargument"> </param>
Public void raisecallbackevent (string eventargument)
{
Strcallresult = voidtt ();
}
/// <Summary>
/// Return the result of callback
/// </Summary>
/// <Returns> </returns>
Public String getcallbackresult ()
{
Return strcallresult;
}
4. For example:
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head Runat = "Server" >
< Title > Untitled page </ Title >
< Script Type = "Text/JavaScript" >
VaR Value_1 = "" ;
Function TT ()
{
//Doother ();
}
Function Processcallbackerror (ARG, context)
{
Alert ('error!');
}
</ Script >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Div >
< Span ID = "Message_1" > </ Span >
< Input Type = "Button" Value = "TT" Onclick = "Callserverdata (value_1, TT )" />
</ Div >
</ Form >
</ Body >
</ Html >
Public String Outputcount = "" ;
Protected Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{}
Clientscriptmanager CSM = Page. clientscript;
Stringbuilder Context = New Stringbuilder ();
Context. append ( " Function returnservervalue (ARG, context) " );
Context. append ( " { " );
Context. append ( " Message_1.innertext = ARG; " );
Context. append ( " Value_1 = ARG; " );
Context. append ( " } " );
String callbackreference = CSM. getcallbackeventreference ( This , " ARG " , " Returnservervalue " , Context. tostring ());
String callbackspt = " Function callserverdata (ARG, context ){ " + Callbackreference + " ;} " ;
CSM. registerclientscriptblock ( This . GetType (), " Callserverdata " , Callbackspt, True );
}
/**/ /// <Summary>
///Number of response received from the client
/// </Summary>
/// <Param name = "eventargument"> </param>
Public Void Raisecallbackevent (string eventargument)
{
Try
{
Outputcount=Eventargument. tostring ();
}
Catch
{
Outputcount= "Output";
}
}
/**/ /// <Summary>
///Define method that returns callback result. (the result of the calculation will be returned)
/// </Summary>
/// <Returns> </returns>
Public String Getcallbackresult ()
{
ReturnOutputcount;
}