views:

627

answers:

2

Hello,
After I load a page through a WebBrowser, and I click a link that fires an AJAX script, I need to detect when the AJAX java script finishes loading HTML changes into a div. Since no DocumentCompleted event is fired when the AJAX script is run, I don't know when it finish running. Is there a way I can attach an event to be raised after I know 100% that the javascript finished changing the div?
The project is in C#.
Thanks

A: 

There is no event. You must patch the JavaScript callback that the browser runs when the reply for the AJAX request comes in. This will contains code like "div.innerHTML = ...". Just put your code below that.

Aaron Digulla
I have no control over the script that's loaded, since it's a third party page.
Pascal
+1  A: 

I did something similar recently (using jQuery):

$('#mydiv').change(function(){
        // do stuff
    }
);

Granted, I also use jQuery to set the HTML of that div. I suppose one non-jQuery approach for you could be to set HTML through your own function, which in turn can fire an onchange event.

@New in town: From my experience that is not correct. I use this on multiple DIVs that never get focus in the first place, and it works well and consistently. The normal behavior is as you describe, and normally only applies to the INPUT and SELECT elements, but this is not the case with jQuery.

Brother Erryn
I'm afraid this The "change" event only fires when the element loses input focus (provided the value has been changed).
Developer Art
Can I do this in .Net?
Pascal
You can use jQuery with .Net. Stackoverflow itself makes heavy use of jQuery.
acrosman