title: Attach an event Handler to mshtml.DispHTMLInputElement
body: <p>I'm busy writing a BHO(Browser Helper Object) in C# and I need to attach events handlers to all onclick events on Input Elements. I'm NOT using the built in webbrowser provided by visual studio, instead I am launching a new instance of the Internet Explorer installed on the clients PC. The problem comes in when using different versions of IE. </p>
  
  <p>In IE7 and IE8 I can do it like this:</p>
  
  <pre><code>public void attachEventHandler(HTMLDocument doc)
  {
    IHTMLElementCollection els = doc.all;
    foreach (IHTMLElement el in els)
    {
      if(el.tagName == "INPUT")
      {
        HTMLInputElementClass inputElement = el as HTMLInputElementClass;
        if (inputElement.IHTMLInputElement_type != "text" &amp;&amp; InputElement.IHTMLInputElement_type != "password")
        {
          inputElement.HTMLButtonElementEvents_Event_onclick += new HTMLButtonElementEvents_onclickEventHandler(buttonElement_HTMLButtonElementEvents_Event_onclick);
        }
      }
    }
  }
  </code></pre>
  
  <p>That works perfectly, the thing is, IE6 throws an error when casting to HTMLInputElementClass, so you are forced to cast to DispHTMLInputElement:</p>
  
  <pre><code>public void attachEventHandler(HTMLDocument doc)
  {
    IHTMLElementCollection els = doc.all;
    foreach (IHTMLElement el in els)
    {
      if(el.tagName == "INPUT")
      {
        DispHTMLInputElement inputElement = el as DispHTMLInputElement;
        if (inputElement.type != "text" &amp;&amp; inputElement.type != "password")
        {
          //attach onclick event handler here
        }
      }
    }
  }
  </code></pre>
  
  <p>The problem is, I cant seem to find a way to attach the event to the DispHTMLInputElement object. Any ideas?</p>