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