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

推荐订阅源

Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
WordPress大学
WordPress大学
爱范儿
爱范儿
小众软件
小众软件
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
博客园_首页
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
MyScale Blog
MyScale Blog
IT之家
IT之家
H
Help Net Security
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
人人都是产品经理
人人都是产品经理

博客园 - 金大侠

基于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;
    }