JS调用CS里的方法:PageMethods
2009-08-14 16:39
267 查看
/article/5298673.html
举个列子:
Default.aspx 里代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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>无标题页</title>
<script type="text/javascript" language="javascript">
<!--
function minbzdm()
{
PageMethods.OK(xxx);
}
function xxx(result)
{
alert(result);
}
//-->
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<div>
<input type='button' value='删除' onclick='minbzdm()' />
</div>
</form>
</body>
</html>
Default.aspx.cs里的代码
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
public static string OK()
{
return "OK";
}
}
通过PageMethods方法来实现JS调用CS,必须注意一下几点:
【1】静态的方法
public static
【2】需要在cs方法上加上:
[System.Web.Services.WebMethod]
【3】需要自定义一个函数接受结果
function xxx(result)
{
alert(result);
}
【4】ScriptManager 必须设置成 EnablePageMethods="true"
Tag标签: ASP.NET,PageMethods,JS调CS
举个列子:
Default.aspx 里代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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>无标题页</title>
<script type="text/javascript" language="javascript">
<!--
function minbzdm()
{
PageMethods.OK(xxx);
}
function xxx(result)
{
alert(result);
}
//-->
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<div>
<input type='button' value='删除' onclick='minbzdm()' />
</div>
</form>
</body>
</html>
Default.aspx.cs里的代码
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
public static string OK()
{
return "OK";
}
}
通过PageMethods方法来实现JS调用CS,必须注意一下几点:
【1】静态的方法
public static
【2】需要在cs方法上加上:
[System.Web.Services.WebMethod]
【3】需要自定义一个函数接受结果
function xxx(result)
{
alert(result);
}
【4】ScriptManager 必须设置成 EnablePageMethods="true"
Tag标签: ASP.NET,PageMethods,JS调CS
相关文章推荐
- JS调用CS里的方法:PageMethods
- 在JS中调用CS里的方法(PageMethods)
- JS调用CS里的方法:PageMethods
- asp.net后台cs中的JSON格式变量在前台Js中调用方法(前后台示例代码)
- JS调用CS里的带参方法
- Ajax客户端异步调用服务端的实现方法(js调用cs文件)
- SilverLight 页面后台方法XX.xaml.cs 创建JS,调用JS ,弹出提示框
- js调用cs中函数的方法及在cs中调用js函数
- javascript 异步调用 后台.cs里的方法 PageMethods如何使用
- js调用cs中函数的方法 和 在cs中调用js函数的方法
- asp.net下利用JS实现对后台CS代码的调用方法
- C#前台js里面使用ajax调用后台aspx.cs方法
- 初学者笔记:框架里,外部js文件调用aspx.cs的方法
- Ajax客户端异步调用服务端方法(js调用cs文件)
- JS调用CS里的方法:WebMethod PageMethods AjaxMethod
- js调用服务器控件cs中的方法(二)
- Ajax 的 asp.net CS调用JS方法,嘿嘿,自己用
- aspx页面前端使用js 调用aspx.cs后台的方法,不回传
- cs文件 调用前台JS函数方法
- [转]javascript 异步调用 后台.cs里的方法 PageMethods如何使用