Hi there,
I have some webcontrols that i want to add dynamically on a page. I
have stored the path / namespace in database (ex
MyNameSpace.WebControls.Control1) to the class/webcontrol.
Lets say i have a column in database that looks like this.
PageID (int) Webcontrol (varchar)
1 MyNameSpace.WebControls.Control1
1 MyNameSpace.WebControls.Control2
Then i want to add the controls dynamically on the page, anyone know
how to do this ?
I guess i have to create a instance of the webcontrol and the add it
with Controls.add() . But how do i create the instance and add it
dynamically from a string?
Hope anyone can help me with this, some expert out there ?? :)
Thanks
Jesper
Joanna Carter [TeamB] - 17 Dec 2005 19:36 GMT
| Lets say i have a column in database that looks like this.
|
[quoted text clipped - 7 lines]
| with Controls.add() . But how do i create the instance and add it
| dynamically from a string?
Assuming the types are declared in the same assembly, then you can use this
version of Activator :
Control newControl = (Control) Activator.CreateInstance(null,
"MyNameSpace.WebControls.Control1");
If the type is in another assembly, then the first parameter should be the
assembly name.
Joanna

Signature
Joanna Carter [TeamB]
Consultant Software Engineer