在我实际开发过程中,刚好遇到c#后端要调用前端js中的方法,所以研究了一下,特分享如下:

前端代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="netToWebFantion.aspx.cs" Inherits="WebApplication2.netToWebFantion" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
function webfunction(par) {
alert("后端调用前端的方法:"+ par);
return false;
}
</script>
<title>c#后端调用前端的方法</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="net"/> </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; namespace WebApplication2
{
public partial class netToWebFantion : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void net(object sender, EventArgs e) {
ClientScript.RegisterStartupScript(this.GetType(), "par", "<script>webfunction('你好吗!')</script>");//webfunction('par')是前台jquery函数
} protected void Button1_Click(object sender, EventArgs e)
{ }
}
}

  核心的代码就是后端:ClientScript.RegisterStartupScript(this.GetType(), "par""<script>webfunction('你好吗!')</script>");

最新文章

  1. ASP.NET MVC5+EF6+EasyUI 后台管理系统(70)-微信公众平台开发-成为开发者
  2. HTTP的长连接和短连接——Node上的测试
  3. typeof的一些兼容性问题
  4. vim 编辑器使用积累(for win)
  5. Java dynamical proxy demo
  6. Js获取当前日期时间及其它操作(转)
  7. POJ1046Color Me Less
  8. ArcObjects SDK(AE)10.1在vs2012安装的方法
  9. angular中的orderBy过滤器使用
  10. 使用EditText搜索listview里面的内容,实现Listview跟随变动的情况
  11. android隐式intent使用场景解析
  12. listview,fragment结合起来
  13. SIX GOD
  14. Fix a Tree
  15. Java数据持久层框架 MyBatis之API学习三(XML 映射配置文件)
  16. Linux二进制分析PDF
  17. Mongo安装与使用
  18. 转 WiFi的STA和AP模式指什么?
  19. Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力
  20. 使用 SSH 和 SFTP 协议

热门文章

  1. LeetCode(Two Sum)
  2. 清除ie10+浏览器的input输入框后面会出现的x号和闭眼logo
  3. 开发SDK注意事项
  4. 第34-1题:LeetCode112. Path Sum I
  5. Java - 静态方法的线程安全问题
  6. PHP生成ZIP压缩文件
  7. CentOS7下安装FTP
  8. Laravel系列之环境搭建 — VirtualBox+Vagrant+Homestead
  9. 判断移动端和pc端最简单的方法
  10. 创建控制器view的几种方式