Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:07:31+00:00 2026-06-08T21:07:31+00:00

Below is the function I use as my browsers’ DocumentCompleted event, and also the

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:07:33+00:00Added an answer on June 8, 2026 at 9:07 pm

    As I recall, DocumentCompleted will fire multiple times if the document being navigated to has iframes that embed other web pages.

    If you only want to receive the event exactly once, just unsubscribe from the DocumentCompleted handler:

    public void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
    {
       var webBrowser = sender as WebBrowser;
       webBrowser.DocumentCompleted -= WebBrowser_DocumentCompleted;
       MessageBox.Show(webBrowser.Url.ToString() );
    }    
    
    private void navBtnClick(object sender, EventArgs e)
    {
         var wbrowser = new WebBrowser();
         wbrowser.DocumentCompleted +=new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
         wbrowser.Navigate("http://www.google.com");
    }
    

    Alternately, you can use System.IObservable and ReactiveExtensions to subscribe to exactly one event firing:

    private void navBtnClick(object sender, EventArgs e)
    {
         var browser = new WebBrowser();
         var docCompleted = Observable.FromEventPattern<WebBrowserDocumentCompletedEventArgs>(browser, "DocumentCompleted")
         docCompleted
             .Take(1) // Take only one event firing
             .Subscribe(i => MessageBox.Show(browser.Url.ToString()));
    
         browser.Navigate("http://www.google.com");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I use jQuery event listener to handle message event, like below: $(window).on('message', function(e)
Below I use the id of a clicked item to tell my function which
I use function below to check connection to WiFi hotspot point: public boolean IsWiFiConnected(){
I'm trying to use the function below to get a DIV to slide-out from
i want to implement next previous functionality using below function. - (void)motionEnded:(UIEventSubtype)mt withEvent:(UIEvent *)event
I'm loading a search result into a table with the JQuery below: $(#searchForm).submit(function (event)
In the code below I use the jQuery ajax() function to do a longpolling
I am trying to use the Microsoft web browser control on a form, however
I use a jquery load function to display weather information below a webcam. It
When I put the below function into leon repl , I get java.lang.IllegalArgumentException: Wrong

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.