dynamically add usercontrol

S

Snorre

Hi
Can anybody explain to me how to dynamically add a usercontrol? When I try
to use the this.Controls.Add the control is added, but none of the
usercontrol member controls are instanciated.

The workaround I have done is to add the control to the aspx and set visible
to false. Not very elegant, so I would really like to add the control from
the codebehind file instead.
 
S

Snorre

I'm doing now :) thanks.

I find it strange though that I have to refer to the ascx file to make the
page aware of the class (through LoadControl). Do you know of a more
sophisticated way to do this?
 
M

Matt

The ascx file is parsed at runtime ... I think it has weird
auto-generated class names like aspx files do ... you could write
custom controls, but then you have to write your own designer classes
.... In my situation, I have a default page with a place holder into
which I dynamically load user controls ... I have a sitemap.xml
document with entries for each user control containing the path, title,
name etc. ... when I want to load a user control I look up the path in
the xml document ... that might give you a little more separation
between your code and physical path to the user controls ... if that's
what you're looking for
 
R

Ron

Hi,
I am trying to accomplish this same task would i really appreciate some code
examples if possible.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top