简体   繁体   English

VB.Net Visual basic 在调用主应用程序例程的 Webbrowser 控件中添加自定义事件

[英]VB.Net Visual basic Adding a custom event in the Webbrowser control that calls a routine in the main application

I'm trying to create and call a custom event in the webbrowser control and everything that I've tried to do causes one error or another when the webpage executes the code.我正在尝试在 webbrowser 控件中创建和调用自定义事件,当网页执行代码时,我尝试执行的所有操作都会导致一个或另一个错误。 What I'm doing is adding a button on each row of a table to facilitate removing that row.我正在做的是在表格的每一行上添加一个按钮,以便于删除该行。 However, the master list of data is in the application.但是,数据的主列表在应用程序中。 When the script in the web page executes, I need to update the master list in the application.当 web 页面中的脚本执行时,我需要更新应用程序中的主列表。 My thoughts were to call a custom event that will be fired in my application where I can do everything that I need to do.我的想法是调用将在我的应用程序中触发的自定义事件,我可以在其中执行我需要执行的所有操作。 I just can't make this work.我就是无法完成这项工作。 here are more details of what I have right now.这是我现在拥有的更多详细信息。 Here is the html code for a given row:这是给定行的 html 代码:

Dim M As String = "</TD><TD>"
RetStr.Append("<TR ID='" & Me.Manifest & "' name='" & Me.Manifest & "'>")
RetStr.Append("<TD>").Append(CompanyID).Append(M).Append(CompanyName).Append(M)
RetStr.Append(ContactName).Append(M).Append(Address1).Append(M).Append(Address2)
RetStr.Append(M).Append(City).Append(M).Append(State).Append(M)
RetStr.Append(Zip).Append(M).Append(Phone).Append("</TD>")
RetStr.Append("<TD><button onclick='deleteRow(""" & Me.Manifest & """)'>Remove</button></TD>")
Return Replace(RetStr.ToString(), "<TD></TD>", "<TD>&nbsp;</TD>")

Here is the code that is in the function:这是 function 中的代码:

Dim HTMLOut As New List(Of String)
HTMLOut.Add("<HEAD>")
HTMLOut.Add("  <SCRIPT language=""VBScript"">")
HTMLOut.Add("    Function deleteRow(rowid)")
HTMLOut.Add("      set row = document.getElementById(rowid)")
HTMLOut.Add("      row.parentNode.removeChild(row)")
HTMLOut.Add("      dispatchEvent(Row)")
HTMLOut.Add("    End Function")
HTMLOut.Add("  </SCRIPT>")
HTMLOut.Add("</HEAD>")
HTMLOut.Add("<BODY>")
HTMLOut.Add("  <TABLE border='1' style='font-size:12;' NAME='Table' ID='TABLE'>")

Here is the code that I have in the application:这是我在应用程序中的代码:

Private Sub WB_DocumentCompleted(sender As Object, e As 
    WebBrowserDocumentCompletedEventArgs) Handles WB.DocumentCompleted
    WB.Document.AttachEventHandler("UpdateList", New EventHandler(
                                   Function(ByVal s As Object, ByVal k As EventArgs)
                                       MsgBox("BOO")
                                       Return True
                                   End Function))
End Sub

Any help in any direction, even if it means I need to change how I'm doing all of this, is very welcomed, There is more code then this.任何方向的任何帮助,即使这意味着我需要改变我做这一切的方式,都非常受欢迎,还有更多的代码。 it's stripped down to what is needed to convey what I'm doing, I know I'm missing something.它被简化为传达我正在做的事情所需的内容,我知道我错过了一些东西。 I just can't figure out what it is;我只是不知道它是什么; The end goal is to update the master list in the application hosting the web browser.最终目标是更新托管 web 浏览器的应用程序中的主列表。 ideas suggestions and comments are always welcome, As a side note, I'm using the web browser control because the final part of the process is to create a file and sftp it to the vender (the application will do this).想法建议和评论总是受欢迎的,作为旁注,我正在使用 web 浏览器控件,因为该过程的最后一部分是创建一个文件并将其 sftp 到供应商(应用程序将执行此操作)。 and print the report.并打印报告。 Thanks!谢谢!

I figured this out.我想通了。 I needed to create a class object, with the comvisible attribute set and add this to the objectForScripting property of the web browser control.我需要创建一个 class object,设置了 comvisible 属性并将其添加到 web 浏览器控件的 objectForScripting 属性。

Imports System.Runtime.InteropServices
<ComVisible(True)> Public Class WBClassCode
    Public Sub UpdateStuff(ByVal Data)
        'My code goes here... called from the web page.
        MsgBox("boo")
    End Sub
End Class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM