Solved

unable to catch triggered event present in web browser control

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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

626 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