Solved

unable to catch triggered event present in web browser control

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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