ScriptManager的EnablePageMethods属性用于设定客户端javascript直接调用服务端静态WebMethod
EnablePageMethods.aspx
<script type="text/javascript">
var txtName;
var lblMsg;
function pageLoad(){
txtName=new Sys.Preview.UI.TextBox($get('txtName'));
lblMsg=new Sys.Preview.UI.Label($get('lblMsg'));
}
function sayHello(){
PageMethods.SayHello(txtName.get_text(),cb_SayHello);
}
function cb_SayHello(result){
lblMsg.set_text(result);
}
</script>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
<Scripts>
<asp:ScriptReference Name="PreviewScript.js" Assembly="Microsoft.Web.Preview" />
</Scripts>
</asp:ScriptManager>
<input type="text" id="txtName" />
<input type="button" value="invoke" onclick="sayHello()" />
<div id="lblMsg"></div>
</div>
</form>
EnablePageMethods.aspx.cs
[System.Web.Services.WebMethod]
public static String SayHello(string name)
{
return "welcome to site " + name;
}
转自:http://www.cnblogs.com/zhangtao/articles/1742128.html