2008-11-10 2 views
3

WebBrowser 컨트롤을 사용하여 winform 앱에 표시 할 웹 페이지가 있습니다. 웹 페이지의 HTML이 변경 될 때 이벤트를 수행해야합니다. 그러나 Ajax를 통해 페이지가 업데이트되는 상황에서 트리거되는 이벤트를 찾을 수 없습니다. DocumentComplete, FileDownloaded 및 ProgressChanged 이벤트는 항상 Ajax 요청에 의해 트리거되지는 않습니다. 이 문제를 해결하기 위해 생각할 수있는 유일한 다른 방법은 문서 개체를 폴링하고 변경 사항을 찾는 것입니다. 그러나, 나는 그것이 아주 좋은 해결책이라고 생각하지 않는다..net 2.0에서 WebBrowser 컨트롤을 사용하여 아약스 업데이트를 어떻게 확인합니까?

아약스 업데이트 또는 다른 방법으로 문제를 해결하기 위해 트리거되는 다른 이벤트가 있습니까?

나는이 타이머를 사용하고 C# 및 .NET 2.0

답변

2

를 사용하여, 단지 특정 요소의 내용의 변화를보고있다.

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를 2 개 가지고 있습니다. 주로 WebBrowser의 DocumentComplete 이벤트와 Timer의 Tick 이벤트에 의존합니다.

각 작업마다 DocumentComplete 또는 Tick 처리기가 필요하며 일반적으로 각 처리기는 RemoveHandler 자체이므로 성공적인 이벤트는 한 번만 처리됩니다. 또한 브라우저와 타이머에서 모든 핸들러를 제거하는 RemoveHandlers라는 프로 시저가 있습니다.

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

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

내 이동은 같은 명령 : 같은

내 AJAX는 일반적으로 볼 명령

관련 문제