js调用C#的办法

Hyso Hyso 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
前台html页面上有个按钮,点击后触发js方法,js方法调用C#,请问要怎么实现
代码如下:

<html>
<head>
<title></title>
<script type="text/javascript">
function bclick() {
document.write("<%=CsharpVoid();%>");
}
</script>
</head>
<body>
<input id="Button1" type="button" value="click" onclick="bclick();" />
</body>
</html>


c#代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Web;


namespace go
{

public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("hello");
}

protected string CsharpVoid()
{
string strCC = "hello";
return strCC;
}
}
}
...全文

相关推荐

评论 12
收藏 已收藏
分享
返回顶部
Hyso
C# 111,128 成员 642,536 内容