473,500 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

added user control not showing up

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

Nov 19 '05 #1
3 6474
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
"PJ6" <no****@nowhere.net> wrote in message
news:O0**************@TK2MSFTNGP15.phx.gbl...
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

Nov 19 '05 #2
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

"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:%2***************@TK2MSFTNGP12.phx.gbl...
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
"PJ6" <no****@nowhere.net> wrote in message
news:O0**************@TK2MSFTNGP15.phx.gbl...
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


Nov 19 '05 #3
PJ6
I got it...

Page.LoadControl
"PJ6" <no****@nowhere.net> wrote in message
news:u1**************@TK2MSFTNGP15.phx.gbl...
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

"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:%2***************@TK2MSFTNGP12.phx.gbl...
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
"PJ6" <no****@nowhere.net> wrote in message
news:O0**************@TK2MSFTNGP15.phx.gbl...
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



Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1995
by: Henke | last post by:
I added a project to my solution that contains a user control. Now I 'd like to add the user control from that project to a form in my solution. The problem is that the control doesn't gets added...
9
2435
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx");...
6
3349
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
3
1259
by: Moojjoo | last post by:
I created an user control (.ascx file) with a DropDownList (DDL) with the following code behide: public string Selected_dept_value() { string dept_value = dept_dropdown.SelectedValue; return...
7
3176
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb --...
4
3000
by: Jordan | last post by:
I need to dynamically add an ImageButton control to a user control and and do some server-side processing when the user clicks it. While I the ImageButton is added to the user control at runtime,...
0
2384
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event,...
1
7588
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
3
3552
by: reelrave | last post by:
Hello All, I've checked around a little on Google (and this group) and have found info similar to what I'm trying to do (i.e., changes that were made in the BE's tables are not reflected in the...
0
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.