Can't use "apply" or "call" functions more than once
I'm using the SHDocVw DLL to open and manipulate an Internet Explorer instance from C#. I need to activate the onkeyup event of several textboxes. This is the code I use:
dynamic userNameTextBox=doc.getElementById(5749).getElementsByTagName("input")[0];
userNameTextBox.value=userName;
userNameTextBox.onkeyup.apply(userNameTextBox);
dynamic passwordTextBox=doc.getElementById(5750).getElementsByTagName("input")[0];
passwordTextBox.value=password;
passwordTextBox.onkeyup.apply(passwordTextBox);
This works for the first call to "apply", but the second call generates an error: "System.MissingMemberException: Error while invoking apply.". This problem also occurs if I u开发者_如何学Cse "call" instead of "apply". However, if I change one of the event invoking functions from "apply" to "call", than it works - but if I try to call this code again in the same instance of my program it throws the same exception. In short - I can't use "apply" or "call" more then once, unless I restart my program.
This problem only occurs with Windows XP+IE8. If I try it in Windows7+IE9 I can use "apply"/"call" as many times as I want.
Is there something I could do that will allow me to use "apply"/"call" more than once, or to invoke events in any other way?
OK, I managed a workaround by invoking the event via JavaScript from the command line(AKA "Navigate"), but I still think there should be a COM(Interop?) based solution to this...
精彩评论