FIX: VB User Control AmbientChanged Event Does Not Fire in IE

ID: Q196219

The information in this article applies to:

SYMPTOMS

Visual Basic user controls that are hosted on an HTML page in Internet Explorer fail to fire the UserControl_AmbientChanged event, even when the ambient properties of the HTML container have clearly changed.

CAUSE

Internet Explorer always passes DISPID_UNKNOWN when calling the OnAmbientPropertyChanged method of the IOleControl interface. While legal according to the rules of this method, it forces controls to query the container back for each property of interest to determine which ambient properties changed.

Visual Basic 5.0 does not handle DISPID_UNKNOWN correctly in OnAmbientPropertyChanged and fails to fire the AmbientChanged event.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been corrected in Visual Studio, 6.0.

MORE INFORMATION

Steps to reproduce behavior

1. Create a new user control project in Visual Basic.

2. Add two command buttons to the default form for the control.

3. Add the following code:

      Private Sub Command1_Click()
         Parent.bgcolor = vbRed
      End Sub

      Private Sub Command2_Click()
         Parent.bgcolor = vbBlue
      End Sub

      Private Sub UserControl_AmbientChanged(PropertyName As String)
         MsgBox "ambient changed"
      End Sub

4. Make the control.

5. Place the control on a Web page (make sure you replace the CLSID in the

   code below):

      <HTML>
      <HEAD><TITLE>Repro of DISPID_UNKNOWN AmbientChanged
      Bug</TITLE></HEAD>
      <BODY>
      <OBJECT ID="AmbientBugTest1" WIDTH=320 HEIGHT=240
         CLASSID="CLSID:<Insert User Control's Class ID here.>">
         <PARAM NAME="_ExtentX" VALUE="8467">
         <PARAM NAME="_ExtentY" VALUE="6350"></OBJECT>
      </BODY>
      </HTML>

6. Click on both command buttons.

RESULT: The ambient back color of the Web page changes, but the AmbientChanged event never fires for the control.

Additional query words:

Keywords          : kbActiveX kbCtrl kbIE300bug kbIE301bug kbIE400bug kbIE401bug kbVBp500bug kbVBp600bug kbVS600fix kbIE302bug kbIE401sp1bug kbIE500dp1bug kbInetDev 
Version           : WINDOWS:3.0,3.01,3.02,4.0,4.01,4.01sp1,5.0,5.0dp1,6.0
Issue type        : kbbug
Solution Type     : kbfix

Last Reviewed: November 25, 1998