added user control not showing up

P

PJ6

I need to add a user control in code, not through the designer. For some
reason it just doesn't show up. Is there some initialization method I need
to call for the control before attemptin to add it?

Paul

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.Controls.Add(New WebUserControl3)
End Sub
 
S

S. Justin Gengo

Paul,

When you add a control dynamically, you have to add it to another control.
In the case of what you're trying, you should be using a placeholder
control.

Put the placeholder on your page where you want the user control to appear.
Then add your dynamic control to the placeholder.

Placeholder1.Controls.Add(MyControl)

If you'd like some working examples I have a few available on my website,
www.aboutfortunate.com, Just click on the "Code Library" link at the top and
then type "Dynamic Control" into the search text box that will appear and
you'll have a few examples.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
P

PJ6

I had already tried that. But just for the heck of it I used a placeholder
control as you suggested. The user control still doesn't show up. Stragenly,
if I change the inheritance from System.Web.UI.UserControl to something else
(such as HtmlInputCheckBox), it shows up just fine...?

Paul
 
P

PJ6

I got it...

Page.LoadControl


PJ6 said:
I had already tried that. But just for the heck of it I used a placeholder
control as you suggested. The user control still doesn't show up.
Stragenly, if I change the inheritance from System.Web.UI.UserControl to
something else (such as HtmlInputCheckBox), it shows up just fine...?

Paul
 

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,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top