你如何检查使用.NET 2.0中的WebBrowser控件的ajax更新? [英] How do you check for ajax updates using a WebBrowser control in .net 2.0?

查看:169
本文介绍了你如何检查使用.NET 2.0中的WebBrowser控件的ajax更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在使用WebBrowser控件一个winform应用程序所显示的网页。我需要执行一个事件时,在网页的变化的HTML;但是,我无法找到所触发的情况下,当页面通过Ajax的更新事件。的的DocumentComplete,FileDownloaded和ProgressChanged事件并不总是由Ajax请求触发。唯一的其他方法可以让我觉得要解决这个问题是轮询文档对象,寻找改变;但是,我不认为这是一个很好的解决方案。

I have a web page that is being displaying in a winform app using the WebBrowser Control. I need to perform an event when the HTML in the web page changes; however, I cannot find an event that is triggered for situations when the pages is updated through Ajax. The DocumentComplete, FileDownloaded, and ProgressChanged events are not always triggered by Ajax requests. The only other way I can think to solve the issue is to poll the document object and look for changes; however, I don't think that is a very good solution.

难道还有其他的事件,我缺少的一个AJAX更新或解决问题的一些其他的方式将被触发?

Is there another event I am missing that will be triggered on an ajax update or some other way to solve the problem?

我使用C#和.NET 2.0

I am using C# and .net 2.0

推荐答案

我一直在使用AA定时器,只是看在一个特定的元素含量的变化。

I have been using a a timer, and just watching for a change in a specific elements content.

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

我有2个对象获得事件处理程序,web浏览器和定时器。 我主要依赖于web浏览器和定时器的Tick事件DocumentComplete事件。

I have 2 objects that get event handlers, the WebBrowser and the Timer. I rely mostly on the DocumentComplete event on the WebBrowser and the Tick event on the Timer.

我写的DocumentComplete或勾选需要每个动作处理程序,每个处理程序将通常RemoveHandler本身,因此一个成功的事件只会一次处理。我也有一个程序叫RemoveHandlers,将删除所有处理程序在浏览器和定时器。

I write DocumentComplete or Tick handlers per action required, and each handler will usually RemoveHandler itself, so a successful event will only be handled once. I also have a procedure called RemoveHandlers that will remove all handlers from the browser and timer.

我的AJAX通常看起来像命令:

My AJAX commands usually look like:

AddHandler AJAXTimer.Tick, AddressOf WaitHandler1
InvokeMember("ContinueButton", "click")
AJAXTimer.Start

我的导航命令,如:

My Navigate commands like:

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

这篇关于你如何检查使用.NET 2.0中的WebBrowser控件的ajax更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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