Advertisement

10.08.2007 at 09:22AM PDT, ID: 22879171
[x]
Attachment Details

How to catch onpropertychange event for DIV HTML element in C# BHO

Asked by peterborchers in Internet Explorer Web Browser, C# Programming Language, Plug Ins

Tags: div

Hi.

I've created a generic DOM event handler in my C# BHO code as follows:

-----
public delegate void DHTMLEvent(IHTMLEventObj e);

/// Generic Event handler for HTML DOM objects.
/// Handles a basic event object which receives an IHTMLEventObj which
/// applies to all document events raised.

[ComVisible(true)]
public class DHTMLEventHandler
{
   public DHTMLEvent Handler;
   HTMLDocument Document;

   public DHTMLEventHandler(mshtml.HTMLDocument doc)
   {
      this.Document = doc;
   }

    [DispId(0)]
    public void Call()
    {
       Handler(Document.parentWindow.@event);
     }
}
----

I've used the code above to sucessfully create an event handler for the onclick event of the document element of the current webbrowser.

I now want to create an event handler to capture when the innerHTML property of a DIV tag contained in the document changes. I've done the following:

--------
IHTMLDocument3 doc2 = (IHTMLDocument3)((IWebBrowser2)pDisp).Document;
DHTMLEventHandler Handler2 = new DHTMLEventHandler(doc2 as mshtml.HTMLDocument);
Handler2.Handler += new DHTMLEvent(OnDocumentPropertyChanged);
doc2.onpropertychange = Handler2;
--------

I've then coded the event handler as follows:

---------
public void OnDocumentPropertyChanged(IHTMLEventObj evo)
{
    IHTMLElement2 element = (IHTMLElement2)evo.srcElement;
           
     if (evo != null)
     {
        MessageBox.Show(evo.srcElement.innerHTML);
      }
}
---------
This code seems to capture when a property changes, but it doesn't correctly reflect the source element that raised the event.

Can anyone help me with identifying the source element that raised the onpropertychanged event or suggest another way of capturing the change of a child DIV tags inner HTML property.

Thanks,
PeterStart Free Trial
 
Loading Advertisement...
 
[+][-]10.28.2007 at 10:17PM PDT, ID: 20167698

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.29.2007 at 01:09AM PDT, ID: 20168063

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.29.2007 at 04:00AM PDT, ID: 20168475

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.29.2007 at 04:12AM PDT, ID: 20168512

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.21.2007 at 12:54AM PST, ID: 20512277

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]12.24.2007 at 08:47PM PST, ID: 20526496

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Internet Explorer Web Browser, C# Programming Language, Plug Ins
Tags: div
Sign Up Now!
Solution Provided By: Computer101
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628