Microsoft KB Archive/259460

= BUG: Date Time Picker Marked Unsafe for Scripting =

Article ID: 259460

Article Last Modified on 6/24/2004

-

APPLIES TO


 * Microsoft Internet Explorer 3.0
 * Microsoft Internet Explorer 3.01
 * Microsoft Internet Explorer 3.02
 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 4.01 Service Pack 1
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 3

-



This article was previously published under Q259460



SYMPTOMS
When you use the Date Time Picker control on a Web page, depending on the security level set in Internet Explorer, Internet Explorer may display the following warning message:

An ActiveX object on this page may be unsafe. Do you want to allow it to be initialized and accessed by scripts?

NOTE: Controls that are inherited from the Date Time Picker may also encounter this problem. For example, the Month View control that comes with MSCOMCTL2.cab is marked as unsafe for initialization and scripting in Internet Explorer 5.0 and 5.5 because it depends on the Date Time Picker control. Other custom controls that are extended from this control may also encounter this problem in which the control is marked as unsafe for scripting.



CAUSE
Date Timer Picker was incorrectly marked as unsafe for scripting. However, it is safe for initialization.

By default, Internet Explorer is configured to disable scripting to an ActiveX control that is not marked safe for scripting. (To change this setting, go to Control Panel, double-click Internet Options, and click the Security tab.)



RESOLUTION
To overcome this problem, wrap Date Time Picker in your own control and expose the appropriate properties and interfaces. Mark it safe by implementing IObjectSafety. See the &quot;More Information&quot; section of this article for detailed information on how to do this.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
Here are the steps that you can to take to simplify the process of wrapping Date Time Picker control in Visual Basic.  Create a new ActiveX control project. From the Projects menu, select Components to add the Microsoft Windows Common Controls-2 6.0 Service Pack 3 (MScomctl.ocx). Click the Date Time Picker control and drag it to your user control. You can resize the control so it fits exactly. Use the object browser to note what methods, events, and properties that you want exposed from the Date Time Picker control. Start the Visual Basic 6 ActiveX Control Interface Wizard. If the Wizard is not listed under the Visual Basic Add-Ins menu, use the Add-In Manager to load it. You can find documentation for the ActiveX Control Interface Wizard in Visual Basic Help.</li> Select the methods, events, and properties that you are want to expose from the Date Time Picker control.</li> On the next screen, add custom members that you want for your control; otherwise leave it blank.</li> On the next screen, map each of the names that you selected in your first screen to the respective control. The public name is what the users will use. Internally, you can map it to the Date Time Picker or your control.

For example, font is a stock property that might be exposed by both the Date Time Picker control as well as your control. Internally, you can just use the Date Time's property. If you want to support it from both your control and the Date Time Picker control, you must add a new property in your control and call the Date Time Control's property internally.

The Wizard will then generate all the code for you. You can do all of this manually, but it's easier to use the Wizard.</li> Besides wrapping the control, you must also implement the IObjectSafety interface for your control. Information on how to do this is in the following Microsoft Knowledge Base article:

182598 HowTo: Implement IObjectSafety in Visual Basic Controls

NOTE: If you have problems with Mktyplib at this step, it may be because it is missing the MSpdb60.dll file. Copy this file from your Visual Basic 6 CD-ROM to the same folder where the Mktyplib utility is installed. Double-click Mktyplib.exe, and it should prompt you for the .odl file as described in Knowledge Base article Q182598.</li></ol>

<div class="references_section">