Loading Custom Server Control from string ..

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)
 
N

Natty Gur

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
 
A

Anders Borum

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? :)
 
J

John Saunders

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.
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top