Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

unable to catch triggered event present in web browser control

Posted on 2014-04-19
2
Medium Priority
?
1,232 Views
Last Modified: 2014-05-04
Hello,

I am using Web Browser control in my WinForms project.

I am calling external site as Web Browser URL.

I could able to catch change in page events of site in Navigated event method of Web Browser.

But I couldn't able to catch AJAX event of page Site (where page is not getting loaded actually, i am selecting a radio button of page and particular part of page like a div is getting refreshed by getting some content from server) in any of the event methods of Web Browser control.

Could anyone help ?

Thanks...
0
Comment
Question by:Md Shah
2 Comments
 
LVL 18

Accepted Solution

by:
dj_alik earned 1000 total points
ID: 40011293
The extensibility object model has no great support for observing scripting execution. It isn't practical, scripting code can run completely asynchronous from the page state at unpredictable times. If there are no reliable DOM modifications made by the script that you can read back then you have no great options beyond just spinning your wheels for a couple of seconds to give it 'enough time'. Shouldn't be a problem given that you run this in a worker thread, just use a System.Windows.Forms.Timer who's Tick event calls Application.ExitThread to end the thread.
Another option:
Don't know if this is exactly what you're after but (providing I know the target's ID or some other characteristic) I do it like this ...
// Get the target
(e.g)

HtmlElement target = _webBrowser.Document.GetElementById("somedivthatwillbepopulatedbytheajaxrequest");
if (target != null)

{
 
target.AttachEventHandler("onpropertychange", new EventHandler(handler));

}

The event will fire whenever the element is (re)populated with HTML so all you do is implement the handler so you can check the InnerHTML or InnerText or whatever it is you need to do, and do it to your hearts content Wink

(e.g)
private void handler(Object sender, EventArgs e)

{

 
HtmlElement div = _webBrowser.Document.GetElementById("somedivthatwillbepopulatedbytheajaxrequest");

if (div == null) return;

String x = div.InnerHtml; // etc

if (!x.Equals("Loading...", StringComparison.InvariantCultureIgnoreCase))

{

 
// Now the element has been populated, do something

}

}
0
 
LVL 8

Author Closing Comment

by:Md Shah
ID: 40041384
Thanks & regret for delay...
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question