Instantiate in code or in ide.

My web application makes use of several home made WebControls.

At the moment I drag and drop the necessary controls from the tool bar onto the web page I’m designing.
That way if those controls have events the web page can ‘handle’ them.
I set all their visible properties to false. Then when I want one, I set it’s visibility property to true and place it in the center of the page.

However I was hoping that I could instantiate my controls in code (as properties of my application) and use them on more than one web page at run time.
but then… How would I handle events? Who is the delegate for those events that the control fires? How do I properly instantiate and display it?

Help?

You’ll use AddHandler. Write a method in your WebPage class whose first parameter in the control. Then

AddHandler myControl.event, AddressOf MyMethod

Syntax is a little weird, and the compiler is not helpful if you mess it up, for example, by putting parenthesis around MyMethod.

ConfigurationContainerControl defined an event called foo. foo has no parameters or return value.
I added a delegate to this class to ‘prototype’ the event.
Called it foo. foo has no parameter an has no return value.
I created a method in this class to handle the event.
I called it fooMethod. fooMethod has no parameters and returns nothing.
WIthin the class I create the instance of the WebControl and try to display it:static cn as ConfigurationContainerControl if cn = nil then cn = new ConfigurationContainerControl AddHandler cn.foo, Address of fooMethod cn.top = 100 cn.Left = 100 cn.Visible = TrueI compiled the code and get the message:[quote]Code, WebPage1.Resized, line 7, Type mismatch error. Expected Delegate( ConfigurationContainerControl.ConfigurationContainerControl ), but got Delegate( ), AddHandler cn.foo, AddressOf fooMethod[/quote]
I’ve forgotten something about creating delegates…

I think I got delegates working from the timer delegate example.
Interesting that the timer example doesn’t seem to declare a delegate in the class.
cn is a class property of class ConfigurationContainerControl

[code]Sub fooMethod(c as ConfigurationContainerControl)
System.DebugLog(“Event received.”)
End Sub

Sub SubmitRequest()
if cn = nil then cn = new ConfigurationContainerControl
cn.top = 100
cn.Left = 100
AddHandler cn.foo, AddressOf fooMethod
cn.Visible = True
End Sub[/code]

Running this causes the debugger to crash sometimes…

And in the end… No Container control shows up.