五.Services属性
Services用来管理对WebService的调用,通过<asp:ServiceReference>标签可以在Services中注册一个WebService,在运行时ScriptManager将为每一个ServiceReference对象生成一个客户端代理,<asp:ServiceReference>标签一个很重要的属性是Path,用来指定WebService的路径,如下所示: 字串8
<asp:ScriptManager ID="SM1" runat="server">
<Services> 
<asp:ServiceReference Path="Service.asmx"/>
</Services>
</asp:ScriptManager>
看一个简单的调用WebService的例子:
WebService如下,注意在WebServiceSample上加ScriptService特性:页面:
[ScriptService]

public class WebServiceSample : System.Web.Services.WebService
{ 
public WebServiceSample()

{ 字串7

//Uncomment the following line if using designed components 
//InitializeComponent(); 
}
[WebMethod]
public string EchoString(String s)

{ 字串1
return "Hello " + s;
}
}
ASPX
字串9

<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> 字串9

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title> 字串9 
</head>

<script type="text/javascript" language="JavaScript">
字串2 
function OnbuttonGo_click() 

{ 字串5
requestSimpleService = WebServiceSample.EchoString(
document.getElementById('inputName').value, //params
OnRequestComplete //Complete event 字串5

);
return false;
}
function OnRequestComplete(result) 字串8 

{ 字串4
alert(result);
}
</script>
<body>
<form id="form1" runat="server"> 字串8 
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebServiceSample.asmx"/> 字串4 
</Services>
</asp:ScriptManager>
<div>
<input type="text" id="inputName" size=20/>
<input id="button" type="button" value="调 用" onclick="return OnbuttonGo_click()" /></div> 字串3 
</form>
</body>
</html>
运行后效果如下:

当然了也可以在运行时动态的在Services中加入ServiceReference,下面看一个运行时动态加入ServiceReference的例子: 字串4

<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> 字串7 

<script runat="server">
字串4 
void Page_Load(object sender, EventArgs e)

{ 字串3

ServiceReference sr = new ServiceReference();
sr.Path = "WebServiceSample.asmx"; 
ScriptManager1.Services.Add(sr);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server">
<title>Untitled Page</title>
</head> 字串3 

<script type="text/javascript" language="JavaScript">

function OnbuttonGo_click() 

{ 字串9 
requestSimpleService = WebServiceSample.EchoString(
document.getElementById('inputName').value, //params
OnRequestComplete //Complete event 字串4

);
return false;
}
字串1

function OnRequestComplete(result) 

{ 字串2

alert(result);
}
</script>

<body> 字串9 

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"> 字串2 
</asp:ScriptManager>
<div>
<input type="text" id="inputName" size=20/> 字串8 
<input id="button" type="button" value="调 用" onclick="return OnbuttonGo_click()" /></div>
</form> 字串7

</body>
</html>
可以看到运行后和在ScriptManager中直接加入的效果是一样的。

六.Scripts属性
关于Scripts属性到后面具体再说吧,最主要的属性有Path指定脚本的路径,ScriptMode指定客户端脚本的模式,它会覆盖ScriptManager中的ScriptMode属性,还有一个属性是IgnoreScriptPath,指定是否忽略掉ScriptManager中的ScriptPath属性。
关于ScriptManager控件就学习到这里了,至于AuthenticationService属性和ProfileService属性都很简单。
示例代码下载:http://www.cnblogs.com/Files/Terrylee/ASPNETAJAXScriptManagerDemo.rar
- 基于Ajax:实时刷新数据,
- 采用dwr ajax和struts开发
- ASP.NET AJAX入门系列(1
- Ajax技术原理简介
- 利用Ajax实现DataGrid无刷
- Struts Ajax简单实现
- AJAX jsp无刷新验证码实例
- Ajax的原理和应用【下】
- ajax中文问题彻底解决
- ajax实现检测用户名是否存
- asp ajax实现分页效果
- 用ASP.NET AJAX实现无刷新
- 《Ajax实战》高清PDF
- ajax jsp 聊天室
- ASP.NET AJAX入门系列(2
- AJAX -惊艳酷炫效果制作者
- Ajax实现分页查询
- 分析xloadtree, 用ajax实
- ASP.NET AJAX入门系列(4
- 对google个性主页的拖拽效

