惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
G
Google Developers Blog
D
Docker
阮一峰的网络日志
阮一峰的网络日志
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
T
The Blog of Author Tim Ferriss
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
I
InfoQ
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
Google DeepMind News
Google DeepMind News

博客园 - 金大侠

基于Extjs web设计器 Sqlserver 差异备份 DataTable使用方法总结 大话prototype Js生成组织结构图 关于读取windows域的用户最后登录时间 经典javascript 一行文字显示不了,用...替代解决方案 .net 发送邮件 .net生成略缩图 将word转换成其它文件 数据挖掘 Web 控件库 SQL Server 2005 在MDX中的新特性 Smart Client 解决导出Excel格式问题 泛型学习 asp.net优化方案 windows2008 IIS7.0使用手记 图片推理1
客户端访问WebService
金大侠 · 2009-06-24 · via 博客园 - 金大侠

客户端访问PageMethod
• 服务器端
– 只能在aspx页面中定义
– 只能是公开静态方法
– 使用WebMethodAttribute标记
– ScriptManager的EnablePageMethods属性设为true
• 客户端
– 通过PageMethods.MethodName访问

在aspx页面:

<form id="form1" runat="server">
     <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
  
  <input type="button" value="Get Current Time" onclick="getCurrentTime()" />
   
  <script language="javascript" type="text/javascript">
      function getCurrentTime()
      {
          PageMethods.GetCurrentTime(getCurrentTimeSucceeded);
      }

      function getCurrentTimeSucceeded(result)
      {
          alert(result);
      }
  </script>

</form>

在.cs :

using System.Web.Services

    [WebMethod]
    public static DateTime GetCurrentTime()
    {
        return DateTime.UtcNow;
    }