After adding a WebBrowser control to my form (VS 2005), and the following 2
lines of code to a click event:
webBrowser1.Navigate(new Uri(NextURL));
String PageData = webBrowser1.DocumentText;
After stepping through the code, noticed that PageData was empty. After the
click event completed processing and exited, the web page was properly
displayed in my form. After entering the click event a 2nd time and
stepping around the Navigate line (so it was not executed), and executing
the next line, discovered that PageData appeared to hold the correct
contents of the web page.
So, my question is - does the click event always have to exit before the web
page can be properly loaded, or is there a way for the Navigate function to
be called sychronously and for the program to wait until the web page is
completely loaded before attempting to acess the DucmentText property?
I'm not really interested in displaying the contents of the webpage. I'm
using the WebBrowser control because I'm working with a web page that uses
cookies and the WebBrowser control appears to handle those cookies properly
by default much like IE. I tried using the WebRequest and WebResponse
classes, but then discovered that these classes don't handle cookies by
default. What I'm really after is obtaining the content of the web page
into a String object so some of the content can be parsed and saved to a
text file.
Thanks for any help in advance.
Bob Bryan