asp:ScriptManager 调用WebService. (ViewManager呈现一个Ascx的执行结果)
http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx
using System; using System.Web.Services; [Microsoft.Web.Script.Services.ScriptService] public class SimpleService : WebService { [WebMethod] public string GetMessage(string name) { return "Hello <strong>" + name + "</strong>, the time here is: " + DateTime.Now.ToShortTimeString(); } }
<html> <head id="Head1" runat="server"> <title>Hello World Service</title> <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript"> function callServer() { SimpleService.GetMessage( $get("Name").value, displayMessageCallback ); } function displayMessageCallback(result) { $get("message").innerHTML = result; } </script> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" > <Services> <asp:ServiceReference Path="~/SimpleService.asmx" /> </Services> </asp:ScriptManager> <h1>Hello World Example</h1> <div> Enter Name: <input id="Name" type="text" /> <a href="BLOCKED SCRIPTcallServer()">Call Server</a> <div id="message"></div> </div> </form> </body> </html>