无法使用“应用”或“呼叫”函数不止一次

发布于 2024-11-27 16:47:48 字数 840 浏览 5 评论 0原文

我正在使用 SHDocVw DLL 从 C# 打开和操作 Internet Explorer 实例。我需要激活几个文本框的 onkeyup 事件。这是我使用的代码:

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

这适用于第一次调用“apply”,但第二次调用会生成错误:“System.MissingMemberException:调用 apply 时出错。”。如果我使用“call”而不是“apply”,也会出现此问题。但是,如果我将事件调用函数之一从“apply”更改为“call”,那么它会起作用 - 但如果我尝试在程序的同一实例中再次调用此代码,它会抛出相同的异常。 简而言之 - 我不能多次使用“应用”或“调用”,除非重新启动我的程序。

此问题仅出现在 Windows XP+IE8 上。如果我在 Windows7+IE9 中尝试,我可以根据需要多次使用“apply”/“call”。

我可以做些什么来让我多次使用“apply”/“call”,或者以任何其他方式调用事件?

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 use "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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咋地 2024-12-04 16:47:48

好的,我通过从命令行通过 JavaScript 调用事件(又名“导航”)来管理解决方法,但我仍然认为应该有一个基于 COM(互操作?)的解决方案......

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文