<!-- 注释 -->
<!-- 在开发中使用较多的情况, 在客户端调用当前页面的服务端方法. -->
<!-- 设置ScriptManager控件的EnablePageMethods属性为:True, 并且在需要使用后台方法前加属性标记[WebMethod] -->
<!-- 服务端方法必须为静态的, 需要客户端调用的才需要设置为静态的; -->
<!-- 注意在服务端类中要打开命名空间using System.Web.Services, WebMethod类在此命名空间中-->
- <script language="javascript" type="text/javascript">
- function ExecuteServerMethod(value)
- {
- PageMethods.ReturnStringServerMethod(value,CallBackResult);
- }
- function CallBackResult(result)
- {
- alert(result);
- }
- </script>
- [WebMethod]
- public static string ReturnStringServerMethod(string str)
- {
- return "Hello " + str;
- }