Solved

unable to catch triggered event present in web browser control

Posted on 2014-04-19
2
1,167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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