creating controls dynamically... again

P

Paul

This was posted yesterday and earlier this morning. Neither of the responses
worked. If you are not certain that something works, why respond? Many see
+'s by these postings and look no further.If you can run this code and don't
get any sort of cast exception, then please respond. I thank you. Otherwise,
please don't waste someone else's time.

DirectCast(o, control) does not work, nor does Me.Controls.Add(o). Had they
tried this they would know.

I'm trying to create a control from a string in a database:

Dim asm As [Assembly] =
Reflection.Assembly.LoadFrom("C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.dll")

Dim typ As Type = asm.GetType("System.Web.UI.WebControls.TextBox", True,
True)

Dim o As Object = Activator.CreateInstance(typ)

Me.Controls.Add(CType(o, Control))

I get "Specified cast is not valid." with the line of code directly above.
How do I/ Can I cast a type to a control?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top