In ASP. net2.0, client callback is used to implement a brushless Newest Application!

Source: Internet
Author: User

In ASP. in net1.1, we can use js to call web services to implement a brushless Newest Application. Now ASP. net2.0 can be implemented using the client callback method, which is more convenient and easy to use. two steps are required to implement the client callback function:

<br>

<br>

<br>

<br>

<br>

<br>

<br>

Stringbuilder sb = new stringbuilder ();

SB. appendformat ("<Table class = '{0}>", "showreview_ascx_distable ");

Foreach (discussionitem item in discussion)

{

// Output html

}

SB. append ("</table> ");

Return sb. tostring ();

}

}

This method receives a parameter from the client and converts it to a reviewid. Based on the reviewid, It queries the relevant data and returns it to the client in HTML format.

2. Implement two client scripts and use page. getcallbackeventreference to describe how the client processes the returned results.

For example:

Page. getcallbackeventreference (this, "topicid", "handleresultfromserver", "context", "handleerrorresultfromserver ")

This indicates the instance of the control that implements icallbackeventhandler,

Topicid indicates the number of string parameters input by the client.

Handleresultfromserver indicates the client script function name for processing the result of successful calls.

Context indicates the passing parameter between the start method of the callback and the method that processes the callback result.

Handleerrorresultfromserver indicates the client script function name for processing the result of a failed call.

Some client scripts are as follows:

Void page_load (Object sender, eventargs E)

{

If (! Ispostback |! This. enableviewstate)

{

Stringbuilder sb = new stringbuilder ();

SB. append ("function loadtree (topicid ){");

SB. append ("Var targetimg = Document. All ('img _ '+ topicid );");

SB. append ("Var targetdiv = Document. All ('tr _ '+ topicid );");

SB. append ("If (targetdiv. style. display! = 'Block '){");

SB. append ("targetdiv. style. Display = \" Block \";");

SB. appendformat ("targetimg. src = \" {0} \ ";", aspnetcommerce. performancecontext. getthemesimagepathforimgtag ("showreview_ascx/Expand-Open.gif "));

SB. append ("targetimg. Alt = \" click to reclaim \";");

SB. append ("Var context = topicid ;");

SB. appendformat ("{0}", page. getcallbackeventreference (this, "topicid", "handleresultfromserver", "context", "handleerrorresultfromserver "));

SB. append ("} else {");

SB. append ("targetdiv. style. Display = \" None \";");

SB. appendformat ("targetimg. src = \" {0} \ ";", aspnetcommerce. performancecontext. getthemesimagepathforimgtag ("showreview_ascx/Expand-Closed.gif "));

SB. append ("targetimg. Alt = \" click to view the discussion \";");

SB. append ("}");

SB. append ("}");

SB. append ("function handleresultfromserver (result, context )");

SB. append ("{");

SB. append ("Var targettd = Document. All ('td _ '+ context );");

SB. append ("targettd. innerhtml = Result ");

// Sb. append ("alert (result );");

SB. append ("}");

SB. append ("function handleerrorresultfromserver (result, context )");

SB. append ("{");

SB. append ("Var targettd = Document. All ('td _ '+ context );");

SB. appendformat ("targettd. innerhtml = '<font color = Red> {0} </font> '",

"Data reading error. Please try again or notify the administrator! ");

SB. append ("}");

Page. clientscript. registerclientscriptblock (this. GetType (), "clientcallback", SB. tostring (), true );

}

}

Related Article

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.