前台页面:WebForm2.aspx

<!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 language="javascript" type="text/javascript">
        //获取WinForm穿过来的值
        function getWinFormValue(winFormValue) {
            document.getElementById("spWinFormValue").innerHTML = winFormValue;
        }
        //调用WinForm里的方法将值传过去
        function SetWinFormValue(WebFormValue) {

            //后台页面的方法 Call
            window.external.Call(WebFormValue);
        }

    </script>
</head>
<body>
    <form />
    </div>
    </form>
</body>
</html>

-------------------------------------------------------------------------------------------------------

Form窗体后台代码:Form2.cs

namespace WindowsFormsApp
{

//申名托管类型,对com是可见的
    [System.Runtime.InteropServices.ComVisible(true)]
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.wbWeb.Navigate(string.Format("javascript:getWinFormValue('{0}');void(0);", this.textBox1.Text));
        }

          //前台js调用的方法

        public void Call(string WebFormValue)
        {
            this.label1.Text = WebFormValue;
        }

        private void Form2_Load(object sender, EventArgs e)
        {

         //此窗体可以通过wbweb控件里面的脚本进行访问
          wbWeb.ObjectForScripting = this;
        }
    }
}

此方法要比前文的 使用webservice实现要简便性能要好!

相关文章:

  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
猜你喜欢
  • 2022-12-23
  • 2021-09-28
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
相关资源
相似解决方案