The server's return will trigger the whole page refresh. How can we just refresh the part? I saw a usage in the book a few days ago.
WebService behavior. I tried it today. The effect is good.
In the web directory, a file webservice. htc is required.
Here you can download: http://msdn.microsoft.com/workshop/author/webservice/webservice.htc
See a WebService file named Service1.asmx:
[WebService (Namespace = "http: // localhost/BehaviorService/")]
Public class TestService: System. Web. Services. WebService
{
/// <Summary>
/// Return the server time
/// </Summary>
[WebMethod]
Public string GetServerTime ()
{
Return DateTime. Now. ToString ();
}
}
Enter an html file in the directory of the same level with the following content:
<Script>
Var intCallId = 0;
Function Init ()
{
GetServerTime ();
SetInterval ("GetServerTime ()", 1000 );
}
Function GetServerTime ()
{
Service. useService ("Service1.asmx? WSDL "," TestService ");
IntCallId = Service. TestService. callService ("GetServerTime ");
}
Function service_result ()
{
If (event. result. error)
{
Showresult. innerText = event. result. errorDetail. string;
}
Else
{
Showresult. innerText = event. result. value;
}
}
</Script>
<Html>
<Body onload = "Init ();">
<Div id = "Service" style = "behavior: url (webservice. htc)" onresult = "service_result ()"> </div>
<Span id = showresult> </span>
</Body>
</Html>
Check http: // localhost/BehaviorService/test1.htm to see the time on a server.
This method can be used to partially refresh the page.
There are two restrictions:
1. The behavior can only be performed using the web service in the domain, because of the built-in security restrictions of DHTML
2. Access types in this way will be restricted, and the behavior supports the basic. net types and their arrays.
For example, dataset and datatable are not supported for complex types.