Dynamic Destructors?

I have a set of dynamically created controls and cannot seem to close them to reset the parent control.

image

It looks like the .Close method cannot be called.

How can I work around this?

Cast them back?

 Weblistbox(controlAt(index)).Close

Or use IsA in combination to check if the control matches

Thanks for the starting point. Here’s what I ended up doing:

  1. Create a Property as a String Array on the parent control:
  2. During the Embed cycle, I get the ControlID of the control right after it is constructed…
  3. And use the array’s AddRow function to add the ControlID to the list.
ParentWebPage.ParentContainerControl1.idlist.AddRow( NewContainerControlRow.ControlID )
  1. When it comes time to destroy the controls specified, I call this code:

    While Me.ControlCount > 0
      
      Var id1 As String
      id1 = ParentWebPage.ParentContainerControl1.idlist(0)
      ParentWebPage.ParentContainerControl1.idlist.RemoveRowAt(0)
      
      Me.ControlWithID(id1).Close
      
    Wend