用asp.net ajax的话相当简单,比如把下拉列表框中选择项的value值传递给服务器端Web Service,处理后再把结果显示到某个 <div>里的例子:
1、给项目增加一个Web Service
MyService.cs
[System.Web.Script.Services.ScriptService]public
class MyService : System.Web.Services.WebService ...{ [WebMethod] public
string GetString(string s) ...{ return
"Hello World "
+ s; //也就是给客户端传来的加个Hello World再返回给客户端。
} }
Default.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function callService(s) { MyService.GetString(s, OnSuccess); } function OnSuccess(result) { $get('result').innerHTML = result; } </script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/MyService.asmx"
/>
</Services>
</asp:ScriptManager>
<div>
<select id="sel">
<option value="1">商品一</option>
<option value="2">商品二</option>
<option value="3">商品三</option>
</select>
<input type="button" onclick="callService($get('sel').value);" value="Go!"
/>
</div>
<div id="result">
</div>
</form>
</body>
</html>