473,408 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ASP.NET can you add controls at run time?

Jax
Lets say i have a list of objects of a variable size.
What I would like to do is create controls and add them to
the web page at run time that represent all the items in
the list.
Problem is everytime i do this:

this.Controls.Add(SomeControl);

The html ends up after the </HTML> tag. Therefore it
doesn't work properly. What do i have to do to make sure
the extra html ends up within the tags?

Many thanks for anyone who clears my cloud of ignorence.

jax

Nov 15 '05 #1
3 1345

"Jax" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Lets say i have a list of objects of a variable size.
What I would like to do is create controls and add them to
the web page at run time that represent all the items in
the list.
Problem is everytime i do this:

this.Controls.Add(SomeControl);

The html ends up after the </HTML> tag. Therefore it
doesn't work properly. What do i have to do to make sure
the extra html ends up within the tags?


Read the documentation.

Use page trace output to see how things are built.

Your problem:

* The complete HTML content of a page is a control within your page*s
controls collection.

So, by adding your control THERE, you add it - beyond the page content.

What you need to od is - add it to a part within the controls hierarchy.

Use a trace (trace.axd, enable it first) to see how the control hierarchy
for your page looks in detail. It is way more complex (as in: thre are way
more controls) than you psosibly think at the moment.

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
Nov 15 '05 #2
Jax
Thankyou for that, it certainly will point me in the right
direction. I just got a new book which i'm sure will also
provide more clarity for my simple mind.
Many thanks.

jax
-----Original Message-----

"Jax" <an*******@discussions.microsoft.com> wrote in messagenews:01****************************@phx.gbl...
Lets say i have a list of objects of a variable size.
What I would like to do is create controls and add them to the web page at run time that represent all the items in
the list.
Problem is everytime i do this:

this.Controls.Add(SomeControl);

The html ends up after the </HTML> tag. Therefore it
doesn't work properly. What do i have to do to make sure
the extra html ends up within the tags?
Read the documentation.

Use page trace output to see how things are built.

Your problem:

* The complete HTML content of a page is a control within

your page*scontrols collection.

So, by adding your control THERE, you add it - beyond the page content.
What you need to od is - add it to a part within the controls hierarchy.
Use a trace (trace.axd, enable it first) to see how the control hierarchyfor your page looks in detail. It is way more complex (as in: thre are waymore controls) than you psosibly think at the moment.

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
.

Nov 15 '05 #3
Jax wrote:
Lets say i have a list of objects of a variable size.
What I would like to do is create controls and add them to
the web page at run time that represent all the items in
the list.
Problem is everytime i do this:

this.Controls.Add(SomeControl);

The html ends up after the </HTML> tag. Therefore it
doesn't work properly. What do i have to do to make sure
the extra html ends up within the tags?

Many thanks for anyone who clears my cloud of ignorence.


Add a PlaceHolder control at the position where you want your list to
appear, then add the dynamically created controls to the PlaceHolder's
control collection.

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Nov 15 '05 #4

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

Similar topics

16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
2
by: Tim Marsden | last post by:
Hi, This is what I am doing, please comment if this is the correct way. I need to add controls to a form dynamically. Within the Page_Load event (is not Postback) I run a routine to create the...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
7
by: Varangian | last post by:
Hello is creating controls at runtime the same as designtime ? will a page be faster if controls are created at designtime rather than at runtime ? If so why ? thanks :)
8
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
4
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.