JS调用PageMethods
http://www.cnblogs.com/Ren_Lei/archive/2010/07/14/1777413.html
JS调用PageMethods
操作步骤:
1。新建一个WebApplication项目,取默认设置。
2。双击设计界面,进入后天代码编辑界面,代码如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
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文件。代码如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
<%@ 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的更多相关文章
- JS调用asp.net后台方法:PageMethods
先帮朋友宣传一下程序人生(http://www.manong123.com)的网站,里面都是开发感悟,开发人员创业,支持一下吧~ 原来是通过PageMethods来实现的. 举个列子: Default ...
- 关于datagrid中控件利用js调用后台方法事件的问题
前台调用后台方法除了用button的click事件,还可以用js调用 一.前台页面如图 需求点击这个按钮触发后台事件,从而能够调用存储过程 <epoint:HyperLinkColumn He ...
- JS调用Android、Ios原生控件
在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...
- 如何通过JS调用某段SQL语句
如何通过JS调用某段SQL语句,这样的需求在报表.数据平台开发中很常见.以报表平台FineReport开发为例,例如在点击某个按钮之后,来判断一下数据库条数,再决定下一步操作.那这在后台如何实现呢? ...
- iOS开发--JS调用原生OC篇
JS调用原生OC篇 方式一(反正我不用) 第一种方式是用JS发起一个假的URL请求,然后利用UIWebView的代理方法拦截这次请求,然后再做相应的处理. 我写了一个简单的HTML网页和一个btn点击 ...
- 通过js调用android原生方法
有时候我们有这样一个需求,监听html中控件的一些事件.例如点击html中某个按钮,跳转到别的activity,复制某段文本. 首先是对webview的设置: myWebView = (WebView ...
- js调用php和php调用js的方法举例
js调用php和php调用js的方法举例1 JS方式调用PHP文件并取得php中的值 举一个简单的例子来说明: 如在页面a.html中用下面这句调用: <script type="te ...
- android webView开发之js调用java代码示例
1.webView设置 webView.getSettings().setJavaScriptEnabled(true);//设置支持js webView.addJavascriptInterface ...
- c#JS调用
using MSScriptControl; using System; using System.Collections.Generic; using System.Reflection; usin ...
随机推荐
- tesseract 4.0 使用
https://blog.csdn.net/andylanzhiyong/article/details/81807425 官方例子: https://github.com/tesseract-ocr ...
- jQuery字体图标的三种方法
BootStrap框架原生图标 在导入BootStrap包的同时,导入bootstrap-3.3.7-dist/css/bootstrap.css层叠样式; <button type=" ...
- Python黑科技 | Python中四种运行其他程序的方式
在Python中,可以方便地使用os模块来运行其他脚本或者程序,这样就可以在脚本中直接使用其他脚本或程序提供的功能,而不必再次编写实现该功能的代码.为了更好地控制运行的进程,可以使用win32proc ...
- npm安装源修改为淘宝源
npm安装源修改为淘宝源 标签(空格分隔): 编译 原:https://cnodejs.org/topic/4f9904f9407edba21468f31e npm安装源修改为淘宝源 镜像使用方法(三 ...
- python正则之模式re.I re.M
re.I 忽略大小写 >>> re.match(r"A","abc",re.I) <_sre.SRE_Match object at 0 ...
- 启动Maven项目时报错Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project **-web: Failed to clean project: Failed to delete E:\**\target\tomcat\logs\access_lo
这类错误 出现这种错误,通常是由于您已启动了另一个tomcat 进程或者运行的javaw.exe进程,导致报错. 解决方法: 1. 鼠标点击 X 进行关闭运行失败的 Console页,(如果运行多次, ...
- MyBatis框架之mybatis逆向工程自动生成代码
http://www.jb51.net/article/82062.htm Mybatis属于半自动ORM,在使用这个框架中,工作量最大的就是书写Mapping的映射文件,由于手动书写很容易出错,我们 ...
- JavaScript-Load-Image
如何将图片显示为canvas https://github.com/blueimp/JavaScript-Load-Image/blob/master/js/load-image-scale.js h ...
- db2缓冲池调优
缓存池: 冲池是内存中的一块区域,db2会将用到数据放到缓冲池中提高性能.缓冲池太小,每次查询仍然要到磁盘中操作,达不到缓冲的效果.缓冲池太大,超出操作系统管理的限制,会导致数据库无法连接的错误. 缓 ...
- 异步任务分发模块Celery
Celery简介 Celery是一个功能完备即插即用的任务队列.它使得我们不需要考虑复杂的问题,使用非常简单. celery适用异步处理问题,当遇到发送邮件.或者文件上传, 图像处理等等一些比较耗时的 ...