d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Why Doesn't This Call Back Function Get Called? > C# Webbrowser Question
Add Reply New Topic New Poll
Member
Posts: 5
Joined: Apr 26 2008
Gold: 0.00
Oct 30 2012 07:08am
Why doesn't this call back function get called?

Basically here is the code surrounding the declaratoini callback method:

Code

webbrowser1 = new WebBrowser();

webbrowser1.LoadCompleted +=webbrowser1_LoadCompleted;

webbrowser1.Navigate(new Uri("http://www.google.com"));


Should there be something more or are they in the wrong order?
The method, webbrowser1_LoadCompleted, is never called. I have put breakpoints in the callback method and the running program never reaches this method:
Code

        void webbrowser1_LoadCompleted(object sender, NavigationEventArgs e)
       {
           .
           .
           .

       }



I must be missing a reference. I do not know what one I am missing. Can you offer a suggestion?

Member
Posts: 827
Joined: Jan 16 2012
Gold: 0.00
Warn: 10%
Member
Posts: 3,064
Joined: Mar 30 2003
Gold: 5,095.00
Oct 31 2012 08:56am
try hooking to the document completed event... then check inside the event to make sure the webbrowser readystate is complete... because i think document completed checks for any document inside the webpage... has downloaded... html... javascript... css.. etc.
Member
Posts: 5
Joined: Apr 26 2008
Gold: 0.00
Nov 7 2012 04:14am
OK, I have an update to make. Now it kind of works and yet it does not work. I am getting close.

I have a C# WPF application which uses a WebBrowser class. I have overwritten the LoadComplete method as well as several other methods to try to get the html content after the pages is loaded:
Code

       String URL = textBox1.Text;

       URL = URL.Replace(' ', '+');
 
       webbrowser1 = new WebBrowser();

       webbrowser1.LoadCompleted += new LoadCompletedEventHandler(webbrowser1_LoadCompleted);
       webbrowser1.Loaded += new RoutedEventHandler(webbrowser1_Loaded);
       webbrowser1.Navigated += webbrowser1_Navigated;

       grd.Children.Add(webbrowser1);

       int i = 0;
       webbrowser1.Navigate(new Uri("https://www.google.com/#q=" + URL + ....


I have put breakpoints in these methods and I have written code to grap the Inner HTML from the HTMLDocument of the WebBrowser class and I have output the html text to different files for each method.

Then I have run the program. While the program runs, I watch the actual program to see if the document loads. The web page that is loading is the results page of a google search query.

Visually, the output is a blank, white page when eaqch method for LoadComplete, Loaded and Navagated is hit while I run through the code. It is only after the methods have been hit (some a couple of times) and the program is idle does the display show the results page.

The HTML code that is output to files does not represent the google search results page. Instead, it represents the google home page and does not have ny of the results. Any ideas? How can I programatically get the results page?


Go Back To Programming & Development Topic List
Add Reply New Topic New Poll