When a project encounters a call to the controlled end, it may sometimes experience network latency. Using ajax.net asynchronous call can improve user experience .....
In fact, the principle is very simple... can be divided:
1. server side:
1) Register Ajax.
Add
<Httphandlers>
<Add verb = "post, get" Path = "ajax/*. ashx" type = "Ajax. pagehandlerfactory, Ajax"/>
</Httphandlers>
2) Add reference Ajax. DLL to the Project
3) Register ajax to the page named webform1
Ajax. Utility. registertypeforajax (typeof (webform1); // Ajax Registration
4) Add the Ajax Method to the page
[Ajaxmethod]
Public String returna ()
{
Thread. Sleep (10000); // for more explicit asynchronous call
Return "Hello World ";
}
2. Client:
1) Add a JS script
<Script language = "JavaScript" type = "text/JavaScript">
Function ()
{
Document. getelementbyid ("label1"). innerhtml = "load .....";
Webform1.returna (B );
}
Function B (RES)
{
Document. getelementbyid ("label1"). innerhtml = res. value;
}
</SCRIPT>
2) place a server control named label1 label on the page.
<Asp: Label id = "label1" runat = "server"> </ASP: Label> <SCRIPT> A (); </SCRIPT>