It seems fairly straightforward, and yet we still get a lot of questions about why users can't do this or that in their applications in the Open event.
If you're creating custom web controls for distribution, there is a way to help users avoid this issue, but it takes careful thought on your part because it's easy to get things out of order if you don't plan ahead.
- Create two private properties on your control:
Private deferredCommands() as String
Private inOpenEvent as Boolean = False
if ControlAvailableInBrowser() or not InOpenEvent then
- Create an event definition for Shown()
- Implement the Shown() event:
if Ubound(deferredCommands)>-1 then
- Create an event definition for Open()
- Implement the Open() event:
InOpenEvent = True
InOpenEvent = False
Using this method, you can be sure that user code will not be sent to the browser before your control and its code reaches the browser.
BE CAREFUL! If you only defer some commands, you could cause user code to execute out of order. For example, if you defer property assignments but not function calls, a function may get called before the user property assignments have been set.