Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用.NET2.0中的WebBrowser控件检查ajax更新?_C#_.net_Ajax_Winforms - Fatal编程技术网

C# 如何使用.NET2.0中的WebBrowser控件检查ajax更新?

C# 如何使用.NET2.0中的WebBrowser控件检查ajax更新?,c#,.net,ajax,winforms,C#,.net,Ajax,Winforms,我有一个网页正在使用WebBrowser控件在winform应用程序中显示。当网页中的HTML更改时,我需要执行一个事件;但是,我找不到通过Ajax更新页面时触发的事件。DocumentComplete、FileDownloaded和ProgressChanged事件并不总是由Ajax请求触发。我能想到的解决问题的唯一其他方法是轮询文档对象并查找更改;然而,我认为这不是一个很好的解决方案 有没有我错过的另一个事件会在ajax更新或其他解决问题的方法中触发 我正在使用C#和.NET2.0,我一直在

我有一个网页正在使用WebBrowser控件在winform应用程序中显示。当网页中的HTML更改时,我需要执行一个事件;但是,我找不到通过Ajax更新页面时触发的事件。DocumentComplete、FileDownloaded和ProgressChanged事件并不总是由Ajax请求触发。我能想到的解决问题的唯一其他方法是轮询文档对象并查找更改;然而,我认为这不是一个很好的解决方案

有没有我错过的另一个事件会在ajax更新或其他解决问题的方法中触发


我正在使用C#和.NET2.0,我一直在使用计时器,只是在观察特定元素内容的变化

Private AJAXTimer As New Timer

Private Sub WaitHandler1(ByVal sender As Object, ByVal e As System.EventArgs)
    'Confirm that your AJAX operation has completed.
    Dim ProgressBar = Browser1.Document.All("progressBar")
    If ProgressBar Is Nothing Then Exit Sub

    If ProgressBar.Style.ToLower.Contains("display: none") Then
        'Stop listening for ticks
        AJAXTimer.Stop()

        'Clear the handler for the tick event so you can reuse the timer.
        RemoveHandler AJAXTimer.Tick, AddressOf CoveragesWait

        'Do what you need to do to the page here...

        'If you will wait for another AJAX event, then set a
        'new handler for your Timer. If you are navigating the
        'page, add a handler to WebBrowser.DocumentComplete
    End If
Exit Sub

Private Function InvokeMember(ByVal FieldName As String, ByVal methodName As String) As Boolean
        Dim Field = Browser1.Document.GetElementById(FieldName)
        If Field Is Nothing Then Return False

        Field.InvokeMember(methodName)

        Return True
    End Function
我有两个获取事件处理程序的对象,WebBrowser和Timer。 我主要依赖WebBrowser上的DocumentComplete事件和计时器上的Tick事件

我为每个需要的操作编写DocumentComplete或Tick处理程序,每个处理程序通常会删除处理程序本身,因此一个成功的事件只处理一次。我还有一个名为RemoveHandlers的过程,它将从浏览器和计时器中删除所有处理程序

我的AJAX命令通常如下所示:

AddHandler AJAXTimer.Tick, AddressOf WaitHandler1
InvokeMember("ContinueButton", "click")
AJAXTimer.Start
我的导航命令如下:

AddHandler Browser1.DocumentComplete, AddressOf AddSocialDocComp
Browser1.Navigate(NextURL) 'or InvokeMember("ControlName", "click") if working on a form.