使用WebBrowser控件的WinForms在asp.net问题 [英] problem using winforms WebBrowser in asp.net

查看:328
本文介绍了使用WebBrowser控件的WinForms在asp.net问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net页面WebBrowser控件。这里是一个简单的code:

i am using the WebBrowser control in asp.net page. here is the simple code:

Public Class _Default
    Inherits System.Web.UI.Page

    Private WithEvents browser As WebBrowser
    Dim th As New Threading.Thread(AddressOf ThreadStart)

    Sub ThreadStart()
        browser = New WebBrowser
        AddHandler browser.DocumentCompleted, AddressOf browser_DocumentCompleted
        browser.Navigate("http://www.someurl.com/")
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        th.SetApartmentState(Threading.ApartmentState.STA)
        th.Start()
        th.Join()
    End Sub

    Private Sub browser_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
        If browser.Document IsNot Nothing Then
                Dim textbox As HtmlElement = browser.Document.GetElementById("txt1")
                textbox.InnerText = "some text"
                Dim button As HtmlElement = browser.Document.GetElementById("btn1")
                button.InvokeMember("click")
        End If
    End Sub
End Class

问题是web浏览器的 DocumentCompleted 事件没有被处理。它看起来像页面请求完成其他任何可能发生之前。
有什么办法解决这个问题?

the problem is that the webbrowser's DocumentCompleted event is not being handled. It looks like the page request finishes before anything else could happen. what's the solution to this problem?

推荐答案

我真的建议你阅读这篇文章(他赢得了代价。)

I really recommend reading this article(He won a price for it..)

在ASP.NET中使用WebBrowser控件
HTTP://www.$c$cproject.com/KB/aspnet/WebBrowser的.aspx

Using the WebBrowser Control in ASP.NET http://www.codeproject.com/KB/aspnet/WebBrowser.aspx

他的解决方案是创建3线程为它工作。

His solution is to create 3 threads for it to work..

这篇关于使用WebBrowser控件的WinForms在asp.net问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆