Solved

unable to catch triggered event present in web browser control

Posted on 2014-04-19
2
1,095 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 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now