creating a control dynamically

  • Thread starter Thread starter Paul
  • Start date Start date
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
 
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?
 
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.
 
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?
 
Back
Top