2

I am unable to fire an "onchange" event in mshtml. Can you please tell me what I am doing wrong here.

HTMLSelectElement element = (HTMLSelectElement)this.HTMLDocument.all.item(controlId, 0);
IHTMLElement e = element as IHTMLElement;
IHTMLDocument4 doc = e.document as IHTMLDocument4;
object dummy = null;
object eventObj = doc.CreateEventObject(ref dummy);
HTMLSelectElementClass se = element as HTMLSelectElementClass;
se.FireEvent("onchange", ref eventObj);

I am getting variable "se" as null. I got this piece of code from another link http://www.itwriting.com/phorum/read.php?3,1507

Can anyone help me with this.

Thanks, Sam

4

2 回答 2

1

由 COM 调用(如 HTMLDocument.all.item)生成的 Runtime Callable Wrapper 对象可以将接口转换转换为 QueryInterface 调用。但是 RCW 不知道如何转换为像 HTMLSelectElementClass 这样的托管类,因此它返回 null。

不是转换为 HTMLSelectElementClass,而是转换为 IHTMLElement3 以调用 fireEvent。

顺便说一句,您的代码在 IE11 模式下不起作用,因为 document.all 已被弃用。请改用 IHTMLDocument3::getElementById。

于 2015-06-06T19:54:00.303 回答
1

我已经尝试了所有盛提到但没有奏效的方法。

通过为“onchange”注入 javascript 代码并执行它来解决此问题。有效。

于 2015-06-19T14:59:56.053 回答