2015-06-04 34 views
2

我無法在mshtml中觸發「onchange」事件。你能告訴我我在這裏做錯了嗎?mshtml fireevent onchange not firing

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); 

我得到變量「se」爲空。我從另一個鏈接得到這段代碼http://www.itwriting.com/phorum/read.php?3,1507

任何人都可以幫助我。

感謝,對象生成 山姆

回答

1

我曾嘗試所有盛提到但沒有工作的人。

此問題已通過爲「onchange」注入JavaScript代碼並執行它來解決。有效。

1

運行時可調用包裝由COM調用像HTMLDocument.all.item可轉換接口鑄造的QueryInterface調用。但是RCW不知道如何轉換爲像HTMLSelectElementClass這樣的託管類,因此它返回null。

不是轉換爲HTMLSelectElementClass,而是轉換爲IHTMLElement3來調用fireEvent。

順便說一句,您的代碼不能在IE11模式下工作,因爲document.all已被棄用。改爲使用IHTMLDocument3 :: getElementById。