Microsoft KB Archive/257952

= PRB: ActiveX Control Creation Timing Problems in Internet Explorer 5 =

Article ID: 257952

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01
 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q257952



SYMPTOMS
An HTML page in Internet Explorer 5 may experience some or all of the following related problems when script attempts to access an ActiveX control on that Web page:
 * An access violation or other browser failure.
 * A script error, "Object Required", on any reference to the control.
 * An unexpected control error.
 * The control appears not to have initialized properly; values are not set as expected or defaults show incorrectly.

These problems are timing-dependent and may seem random. They may seem to occur with some uses of the control and not others and be related to the speed with which the Web page loads. These symptoms don't occur in previous versions of Internet Explorer.



CAUSE
Controls may not be completely inplace activated before the window.onload event fires and script begins to access them. (ActiveX controls intended for use in Web pages must be designed to handle this condition.)



RESOLUTION
To resolve these problems, control authors must redesign their controls to handle automation calls that may be invoked before the control is fully inplace active. For additional information on this procedure, click the article number below to view the article in the Microsoft Knowledge Base:

195188 PRB: ActiveX Control Window Is Not Created Until Visible in Internet Explorer

For Web page authors who use a standard ActiveX control that is provided by Microsoft or another company that can't be corrected immediately, the only resolution is to avoid scripting the control until it is fully created, which is not guaranteed until after the control has returned from the window.onload event.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
Because this problem is timing-dependent, it is not possible to provide a guaranteed reproduction scenario. Most Web pages that experience a problem are of the following form:  Repro for IE5 ActiveX control problem     MyControl1.DoSomething;  </BODY> </HTML> The script call to "MyControl1.DoSomething" results in the symptoms described previously.

Example Resolution
First, move all script code that uses any ActiveX control on the page out of the window.onload handler or inline script. If there is initialization script code for a control that must be run at load time, move it to a specific function or subroutine. Create a script timer to call this function in window.onload and set it for approximately half a second.

Here is an example workaround for this page: <HTML> Fix for IE5 ActiveX control problem</TITLE></HEAD> <BODY>  </OBJECT> <SCRIPT LANGUAGE="JavaScript"> function InitializeControl {  MyControl1.DoSomething; } </SCRIPT> <SCRIPT FOR="window" EVENT="onload" LANGUAGE="JavaScript"> window.setTimeout("InitializeControl", 500); </SCRIPT> </BODY> </HTML>

Keywords: kbprb KB257952

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.