110,534
社区成员
发帖
与我相关
我的任务
分享
<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>
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;
}
}
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.GetElementById("bt_serch").Click += new HtmlElementEventHandler(SearchNoteList);
}
private void SearchNoteList(object ob, HtmlElementEventArgs e) //点击了【搜索】按钮,查找关键字
{
HtmlElement el = (HtmlElement)ob;
...
}
//winform执行js函数
public object ExecJSfuncion(string func, object[] param)
{
return this.webBrowser1.Document.InvokeScript(func, param);
}
//在主界面函数前添加
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class MainForm : Form
{}
PageMethods.CsharpVoid(funReady,funError);
function funReady(result){
alert(result);
}
function funError(err){
alert("Error:" + err._message );
}
[System.Web.Services.WebMethod]
public static string CsharpVoid()
{
string strCC = "hello";
return strCC;
}