Below is the function I use as my browsers' DocumentCompleted
event, and also the navBtnClick()
method which is responsible for creating the web browser and navigating to a specific url.
public void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
MessageBox.Show( ((WebBrowser)sender).Url.ToString() );
}
private void navBtnClick(object sender, EventArgs e)
{
WebBrowser wbrowser = new WebBrowser();
wbrowser.DocumentCompleted +=new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
wbrowser.Navigate("http://www.google.com");
}
Now after this line wbrowser.Navigate("http://www.google.com");
is executed, there is a message box correctly showing the url, and then after a while another message box shows with the same url. So, what happens is, whatever is on the DocumentCompleted
event handler, gets executed twice. Can someone help me make it execute once only?