views:

854

answers:

7

The VB.Net desktop app uses the IE browser control to navigate the web. When a normal page loads the document_complete event fires and I can read the resulting page and go from there. The issue I am having is that the page I am driving is written with AJAX, so the document complete event never fires. Furthermore, when you view the source of the page after it loaded a new portion via AJAX, it hasn't change. How are people handling this? What are my options?

A: 

You need to interact with the Javascript code in the website using the methods on HtmlDocument.

SLaks
Am I monitoring another event in VB.Net? Can you provide an example?
ajl
A: 

I have seen this kind of behavior with C# when some AJAX scripts created a race condition. Adding the defer attribute to the script tag helped in that case. YMMV.

Robusto
I think you're misunderstanding the question.
SLaks
I can't edit the web site - it's not mine. I am simply driving the control around and working with the resulting pages.
ajl
A: 

Not sure if this will work.

When the Ajax call completes, add a random anchor hash to the URL like so: foo.html#23234 then add your code to the NavigateComplete2 event.

http://msdn.microsoft.com/en-us/library/aa768334%28VS.85%29.aspx

Raj Kaimal
But how do I know when the AJAX call is complete? Does something fire?
ajl
Not sure what framework you are using but with the core api, you know the load is complete in the onreadystatechange event function onSumResponse() { if (xhReq.readyState != 4) { return; } var serverResponse = xhReq.responseText; ... } ... var xhReq = createXMLHttpRequest(); xhReq.open("GET", "sumGet.phtml?figure1=5 xhReq.onreadystatechange = onSumResponse; xhReq.send(null);ref: http://ajaxpatterns.org/XMLHttpRequest_Call
Raj Kaimal
A: 

I'm guessing that the page your load in your windows app does an AJAX call, which appears to refresh the page. In that case, the document_complete event isn't fired, because the webpage itself isn't refreshed, but a portion of the page.

I found a similar question about this problem, with an accepted answer in VB.Net.

Prutswonder
A: 

AJL - I'm having the same exact same problem. Do you have a working example to resolve this issue? Any help would be greatly appreciated.

markakahunter
+1  A: 

This solution might solve your problem. prerequists: AxwebBrowser control, reference to mshtml.dll

Dim axmshtml As mshtml.HTMLDocument = YourAxWebBrowserControl.Document

Dim HTMLSource As String = axmshtml.body.innerHTML 'html source, including DOM changes

If you know what you are looking for you can put the above code in a timer/loop
and simply monitor the page source for changes.

Bobby
A: 

You can use the ProgressChanged event, it seems to fire during ajax calls

jethomas44