前台页面信息:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="QianBao.Dictionary.WebForm1" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<script type="text/javascript">
function tips() {
var txt = document.getElementById("TextBox1").value;
PageMethods.aa(txt, funRight); }
function funRight(val) //回调函数,用val接受后台代码aa的执行结果
{
alert(val);
}
</script>
<asp:Label ID="Label1" runat="server" Text="请输入信息:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="提交" OnClientClick="tips()" />
</div>
</form>
</body>
</html>

后台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; using System.Web.Services; namespace QianBao.Dictionary
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
[WebMethod]
public static string aa(string str )
{
return "您输入的是:" + str;
}
}
}

注:前端页面需要引用ScriptManager服务器控件,并且将EnablePageMethods设置为true

PageMethods方法

PageMethods.FunctionName(Parameter1,Parameter2...,funRight,funError,userContext);

parameter是Function的参数 object、Array类型

funRight是方法调用成功的回调函数,对返回值进行处理

funError是后台方法报错后,调用js处理

userContext是可以传递给SuccessMethod方法,或是FailedMethod方法的任意内容。

最新文章

  1. C# Azure 存储-Blob
  2. JS弹出浮层
  3. (转)java缓存技术,记录
  4. 在Abp中执行sql语句
  5. ZOJ 3494 (AC自动机+高精度数位DP)
  6. BZOJ3206 [Apio2013]道路费用
  7. 【HTML】Advanced6:HTML5 Forms Pt. 1: Input Types
  8. NSTimer你真的会用了吗
  9. 利用libcurl进行post
  10. C++ - 复制容器(container)的元素至还有一个容器
  11. Android OpenGL ES 入门系列(二) --- 环境搭建
  12. wdcp lanmp 安装+搭建网站+安全狗安装 详细实用
  13. Selenium基础知识(九)验证码
  14. django面试题必问
  15. 做为一个.net码农,打开公司的一个项目,大叔我哭了
  16. Spark的运行模式(1)--Local和Standalone
  17. 用MyEclipse JPA创建项目(一)
  18. 调整Linux的最大文件打开数
  19. php static 变量用法
  20. mysql 数据操作 单表查询 where约束 练习

热门文章

  1. systemtap --diskio
  2. eclipse的Java项目修改后要不要重启tomcat问题
  3. Python实例--C#执行Python脚本,传参
  4. [Vue-rx] Share RxJS Streams to Avoid Multiple Requests in Vue.js
  5. HDU 5358 多校第6场 First One
  6. PLY格式文件具体解释
  7. Android图形显示系统——上层显示1:界面绘制大纲
  8. 浏览器的多线程和js的单线程--前端易混淆知识科普(一)
  9. URAL 1326. Bottle Taps(简单的状压dp)
  10. springmvc的执行流程详解