当前位置: 首页 > news >正文

JS调用PageMethods

操作步骤:

1。新建一个WebApplication项目,取默认设置。

2。双击设计界面,进入后天代码编辑界面,代码如下:

 

using System;

using System.Web.Services;

namespace WebApplication1

{

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

[WebMethod]

public static string TestFunc1()

{

return "This is the returns of behind code function one";

}

[WebMethod]

public static string TestFunc2(string str)

{

return "This is the returns of behind code function two!You give me the string :"+str;

}

}

}

3。准备好PageMethods后,编辑Default.aspx文件。代码如下:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>JS调用后台PageMethods</title>

<script type="text/javascript" language="javascript">

function TheJSTestfunc1()

{

PageMethods.TestFunc1(onsuccess);

}

function TheJSTestfunc2()

{

var txt=document.getElementById('Text1').value;

PageMethods.TestFunc2(txt,onsuccess);

}

function onsuccess(value)

{  

document.getElementById('divResult').innerHTML=value;

}

</script>

</head>

<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">

</asp:ScriptManager>

<div>

<input id="Button1" type="button" value="button" onclick="TheJSTestfunc1()" />

<hr />

<input id="Text1" type="text" /><input id="Button2" type="button" value="button" onclick="TheJSTestfunc2()" />

<hr />

The returns :<div id="divResult"></div>

</div>

</form>

</body>

</html>

操作说明:

其实与我的另一篇随笔[JS调用WebService]里面提到的相似。

1.页面中需要添加ScriptManager组件,然后将它的EnablePageMethods属性设置为True。

2.编写页面方法时也要向调用WebService一样,在方法前加[WebMethod],调用WebService与PageMethods其实是同出一辙,原理都是一样的。

工作原理:

  暂无。

源码下载:

JS调用PageMethods

 

http://www.cnblogs.com/Ren_Lei/archive/2010/07/14/1777413.html

相关文章:

  • String与string的区别(注意大小写)
  • javascript-按圆形排列DIV元素(二)---- 运动
  • LoadRunner之自定义HTTP请求
  • Shell脚本之sed篇
  • DFS建立之之FRSM磁盘配额与文件过滤
  • JavaScript文本框统计字数
  • 脚本编程基础知识点总结
  • LoadRunner检查点
  • 05-Windows Server 2012 新特性 ---- 集成的ISCSI网络存储
  • 观察坐标系
  • Windows程序员需要学什么
  • 统计难题(trie树)
  • 爱上MVC3系列~Razor页面中的共享namespace不起作用了(解决自定义扩展方法不能识别的问题)...
  • js或jquery实现页面打印可局部打印
  • Windows 8 Relase Preview的安装
  • php的引用
  • CSS中外联样式表代表的含义
  • ECMAScript6(0):ES6简明参考手册
  • JavaScript/HTML5图表开发工具JavaScript Charts v3.19.6发布【附下载】
  • Mysql数据库的条件查询语句
  • PhantomJS 安装
  • React-Native - 收藏集 - 掘金
  • Service Worker
  • session共享问题解决方案
  • tweak 支持第三方库
  • UMLCHINA 首席专家潘加宇鼎力推荐
  • zookeeper系列(七)实战分布式命名服务
  • 机器学习中为什么要做归一化normalization
  • 模仿 Go Sort 排序接口实现的自定义排序
  • 前端临床手札——文件上传
  • 容器化应用: 在阿里云搭建多节点 Openshift 集群
  • 微信小程序实战练习(仿五洲到家微信版)
  • 我这样减少了26.5M Java内存!
  • 想晋级高级工程师只知道表面是不够的!Git内部原理介绍
  • elasticsearch-head插件安装
  • ​configparser --- 配置文件解析器​
  • ​ssh-keyscan命令--Linux命令应用大词典729个命令解读
  • ![CDATA[ ]] 是什么东东
  • (1)SpringCloud 整合Python
  • (C语言)共用体union的用法举例
  • (DenseNet)Densely Connected Convolutional Networks--Gao Huang
  • (done) ROC曲线 和 AUC值 分别是什么?
  • (ZT)出版业改革:该死的死,该生的生
  • (附源码)计算机毕业设计SSM在线影视购票系统
  • (九)One-Wire总线-DS18B20
  • (六)激光线扫描-三维重建
  • (七)MySQL是如何将LRU链表的使用性能优化到极致的?
  • (原創) 如何動態建立二維陣列(多維陣列)? (.NET) (C#)
  • * 论文笔记 【Wide Deep Learning for Recommender Systems】
  • .NET 3.0 Framework已经被添加到WindowUpdate
  • .net打印*三角形
  • .Net的C#语言取月份数值对应的MonthName值
  • /usr/bin/env: node: No such file or directory
  • @Autowired自动装配
  • [Android View] 可绘制形状 (Shape Xml)