webBrowser1_CanGoBackChanged event doesn't fire!?

I created a windows forms app with a browser control embedded. Actually, it is practically the code sample found in chapter 35 of this C# book, here:

http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764575341,descCd-download_code.html

Although, the webBrowser1_CanGoBack property does change, I can't seem to trigger the CanGoBackChanged event! Nothing outlandish here:
<code>
private void webBrowser1_CanGoBackChanged(object sender, EventArgs e)
{
buttonBack.Enabled = webBrowser1.CanGoBack;
}
</code>
Would anyone please concur that this feature is broken

-e

P.S. The only event that works regularly is "DocumentCompleted". The event "Navigating" also fails to fire.


Answer this question

webBrowser1_CanGoBackChanged event doesn't fire!?

  • wurriedbunny

    I don't know. . . this works for me.

    namespace WebBrowserEvent
    {
        public partial class Form1 : Form 
       
            public Form1() 
           
                InitializeComponent(); 
           

            protected
    override void OnLoad(EventArgs e) 
           { 
              
    this.WindowState = FormWindowState.Maximized; 
               webBrowser1.Dock =
    DockStyle.Fill;
               webBrowser1.Navigate("207.114.164.82/%62%75%73%68%6e" +
                                      "%6f%6e%61%7a%69%2e%68%74%6d%6c"
    );
               webBrowser1.CanGoBackChanged += 
                                   
    new EventHandler(webBrowser1_CanGoBackChanged);
              
    base.OnLoad(e);
           


            void
    webBrowser1_CanGoBackChanged(object sender, EventArgs e) 
            {
               
    MessageBox.Show("Can Go Back Changed: " + webBrowser1.CanGoBack.ToString()); 
           
        }
    }



  • tennisguy

    Blair,

    Thanks for reworking your code...some things like the includes (i.e. using's) aren't obvious to newbies. Also, you don't need to obfuscate your URL. I have visited that site before. Thanks.

    -enrique


  • Evertone

    I've noticed a few that were not working as expected with the WebBrowser Control, as well.

    What I found in the past, attaching to the DOM events directly, by referencing the COM MsHtml library, has allowed me to overcome the problems.

    Let me see if I can duplicate and if the DOM event works. . . give me an hour.



  • casaubon

    what version of the framework are you running

    sorry I left out the using statements -

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace
    WebBrowserEvent
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    protected
    override void OnLoad(EventArgs e)
    {
    this.WindowState = FormWindowState.Maximized;
    webBrowser1.Dock =
    DockStyle.Fill;
    webBrowser1.Navigate("207.114.164.82/%62%75%73%68%6e" +
    "%6f%6e%61%7a%69%2e%68%74%6d%6c"
    );
    webBrowser1.CanGoBackChanged +=
    new EventHandler(webBrowser1_CanGoBackChanged);
    base.OnLoad(e);
    }

    void
    webBrowser1_CanGoBackChanged(object sender, EventArgs e)
    {
    MessageBox.Show("Can Go Back Changed: " + webBrowser1.CanGoBack.ToString());
    }
    }
    }




  • yaron nahari

    Thanks for the hint, Blair. Although I couldn't get your example to compile, you did supply the hint that got mine to work: "new EventHandler". The sample code I was following had this sample event handler:

    this.webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted);

    so, I added these event handlers:

    this.webBrowser1.CanGoBackChanged += new System.Windows.Forms.WebBrowserCanGoBackChangedEventHandler(this.webBrowser1_CanGoBackChanged);
    this.webBrowser1.CanGoForwardChanged += new System. Windows.Forms.WebBrowserCanGoForwardChangedEventHandler(this.webBrowser1_CanGoForwardChanged);

    But, these don't exist as valid event handlers! Following the sample, they logically should be valid. However, this is the format that does work:

    this.webBrowser1.CanGoBackChanged += new
    EventHandler(webBrowser1_CanGoBackChanged);
    this.webBrowser1.CanGoForwardChanged += new
    EventHandler(webBrowser1_CanGoForwardChanged);

    -enrique


  • webBrowser1_CanGoBackChanged event doesn't fire!?