Loading Custom Server Control from string ..

  • Thread starter Thread starter Anders Borum
  • Start date Start date
A

Anders Borum

Hello!

I'm looking for the best way to load a custom server control defined by a
string (not a user-control - defined by the .ascx extension). The source for
the control is defined in e.g. a database and defines the namespace and
class for the control to be loaded.

Are we simply talking about loading assemblies here?

C#:
// Get source for control
string controlSrc = "SphereWorks.Controls.RSSFeedDisplay";

// Here's the interesting part (?)
Control loadedControl = ?

Controls.Add(loadedControl);

Thanks in advance. It's a quite interesting discussion, so I hope someone'll
join in =o)
 
Why not to load your custom control as any server control :

SphereWorks.Controls.RSSFeedDisplay MyControl = new
SphereWorks.Controls.RSSFeedDisplay();

MyControl .Visible = true;

Controls.Add(MyControl );




Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 
Hello!
Why not to load your custom control as any server control :

SphereWorks.Controls.RSSFeedDisplay MyControl = new
SphereWorks.Controls.RSSFeedDisplay();

MyControl .Visible = true;

Controls.Add(MyControl );

Thanks for the input, but I need to load (create an instance of) the control
from a string definition (coming from a database). The framework I've built
accepts both user controls and custom server controls, which - to your
knowledge I'm sure - isn't loadable using the LoadControl() method.

Any ideas? :-)
 
Anders Borum said:
Hello!


Thanks for the input, but I need to load (create an instance of) the control
from a string definition (coming from a database). The framework I've built
accepts both user controls and custom server controls, which - to your
knowledge I'm sure - isn't loadable using the LoadControl() method.

Any ideas? :-)

Take a look at Activator.CreateInstance.
 
Back
Top