Add Dynamic Control Question

Please could someone clever just confirm I’m doing this right?
I want to add a small collection of controls dynamically to a page when a button is pressed.
The collection of controls are on a WebContainer designed in the IDE and called cc1
On the Action event of my button, I am doing this -

Dim nc As New cc1
nc.embedWithin(WebPage1,...blah)

It seems to work, but is that the recommended way to do it?

This ought to work fine. Although, if you will need to close the container later, you may want to keep a reference to it as a property on the page.

make sure you use Self instead of WebPage1 there. Otherwise you risk creating a new instance.

@Paul - yes, I am keeping a lot of info in a separate array as each new instance is a kind of flowchart style block with parameters that will need to be traversed later.

@ Greg - thanks, will do. Could you explain under what circumstances that would create a new instance, please? Just to further my understanding…

Thanks,

So the thing is that WebPage1 is an object, not an instance per se, so by using WebPage1 there, you’re asking the framework to figure out that you’re in a session, and that you want the current instance. If there was no session for some reason ( or no WebPage1 instance) your code would cause the framework to create a new one for you (assuming you have implicit instance checked). Remember, there could be multiple instances of WebPage1 within a session if you’re reusing the code. I suspect you’ll find it safer to use Self.

Ah, I see. Thanks for that.