creating a control dynamically

P

Paul

I'm trying to create 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))

How do I get from object to control? TIA
 
H

Herfried K. Wagner [MVP]

Paul said:
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))

How do I get from object to control? TIA

What doesn't work?
 
N

Nak

Hi Paul,

When I've done this in the past for a plugin engine I've used
Activator.CreateInstanceFrom to get a remoting ObjectHandle. The called the
unwrap method of the object handle and type casted it to my desired type.
I'm sure you must be able to do this in a similar way although I can't test
the web form part unfortunately :-(

Nick.
 
P

Paul

I get "Specified cast is not valid." with CType(o, Control)). How do I get
cast a type to a control?

Herfried K. Wagner said:
Paul said:
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))

How do I get from object to control? TIA

What doesn't work?
 

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