NET 2.0 callback Process

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.