471,313 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,313 software developers and data experts.

(Hard one,any expert out threre ? ) Create object from string ? add webcontrols dynamically on page.

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

Dec 17 '05 #1
1 1145
<je************@yahoo.se> a écrit dans le message de news:
11**********************@g43g2000cwa.googlegroups. com...

| 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?

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

--
Joanna Carter [TeamB]
Consultant Software Engineer
Dec 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jonah Olsson | last post: by
3 posts views Thread by msnews.microsoft.com | last post: by
2 posts views Thread by Junsan | last post: by
3 posts views Thread by Administrator | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.