473,608 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.Net 2.0 - Retrieve list of controls in place holder

I use a place holder to load different user controls on an .aspx page.

Let's call this default.aspx.

Each user controls contains about a dozen different ASP.Net controls.

My question is, how can I retrieve the list of controls from
default.aspx?

Nov 6 '06 #1
3 3428
Hi,

JimCinLA wrote:
I use a place holder to load different user controls on an .aspx page.

Let's call this default.aspx.

Each user controls contains about a dozen different ASP.Net controls.

My question is, how can I retrieve the list of controls from
default.aspx?
the controls-collection applies to all controls. That is, if you have i.e.
a panel, you can loop through all its contained controls using i.e.
for i as integer=0 to pnlYourPanel.co ntrols.count-1
response.write pnlYourPanel.co ntrols(i).id
next
(A for-each is possible as well.)

Cheers,
Olaf
--
My .02: www.Resources.IntuiDev.com
Nov 6 '06 #2

Olaf Rabbachin wrote:
Hi,

JimCinLA wrote:
I use a place holder to load different user controls on an .aspx page.

Let's call this default.aspx.

Each user controls contains about a dozen different ASP.Net controls.

My question is, how can I retrieve the list of controls from
default.aspx?

the controls-collection applies to all controls. That is, if you have i.e.
a panel, you can loop through all its contained controls using i.e.
for i as integer=0 to pnlYourPanel.co ntrols.count-1
response.write pnlYourPanel.co ntrols(i).id
next
(A for-each is possible as well.)

Cheers,
Olaf
--
My .02: www.Resources.IntuiDev.com
Olaf,

Thanks, but I really didn't word the question quite correctly.

My user control contains about 45 ASP.Net controls such as labels,
buttons, and drop down lists. (This doesn't include the list items
within the DDLs which are also ASP.Net controls.)

In default.aspx, I want to find all the controls that have been loaded
into the placeholder. But for some reason, I can only list about
a third of them using the following code...

ctl_1 = Page.LoadContro l("~/UserControls/MyControl.ascx" );
plcHol1.Control s.Add (ctl_1);

// ...

foreach (Control ctl in ctl_1.Controls)
Response.Write( ctl_1.ID + "<br>");

Every control has an ID.

But I can still find a specific control which doesn't appear using
the above by using refraction. That is,

if (ctl_1.FindCont rol("lblSomeLab el") != null)
Write.Response ("lblSomeLab el exists.")

What I think is happening is that controls that are contained
in tables nested inside tables don't show in the Controls
collection, but can be "smoked" out using refraction.
Of course I don't want to resort to this, because it's
slow, and I have to run this process many times.

Any ideas? Or does anyone see something obvious that
I'm overlooking?

Nov 6 '06 #3
If you want to find nested controls, use a nested loop.

protected void ListAllControls (Control root, int level)
{
Response.Write( string.Format(" {0}{1}<br />", root.ID, new string(' ',
level * 3)));
foreach(Control child in root.Controls)
{
ListAllControls (child, level + 1);
}
}

ListAllControls (myPanel, 0) should then give you

myPanel
mySubControl1
mySubSubControl
myOtherSubSubCo ntrol
mySubControl2
...

JimCinLA wrote:
Olaf Rabbachin wrote:
Hi,

JimCinLA wrote:
I use a place holder to load different user controls on an .aspx page.
>
Let's call this default.aspx.
>
Each user controls contains about a dozen different ASP.Net controls.
>
My question is, how can I retrieve the list of controls from
default.aspx?
the controls-collection applies to all controls. That is, if you have i.e.
a panel, you can loop through all its contained controls using i.e.
for i as integer=0 to pnlYourPanel.co ntrols.count-1
response.write pnlYourPanel.co ntrols(i).id
next
(A for-each is possible as well.)

Cheers,
Olaf
--
My .02: www.Resources.IntuiDev.com

Olaf,

Thanks, but I really didn't word the question quite correctly.

My user control contains about 45 ASP.Net controls such as labels,
buttons, and drop down lists. (This doesn't include the list items
within the DDLs which are also ASP.Net controls.)

In default.aspx, I want to find all the controls that have been loaded
into the placeholder. But for some reason, I can only list about
a third of them using the following code...

ctl_1 = Page.LoadContro l("~/UserControls/MyControl.ascx" );
plcHol1.Control s.Add (ctl_1);

// ...

foreach (Control ctl in ctl_1.Controls)
Response.Write( ctl_1.ID + "<br>");

Every control has an ID.

But I can still find a specific control which doesn't appear using
the above by using refraction. That is,

if (ctl_1.FindCont rol("lblSomeLab el") != null)
Write.Response ("lblSomeLab el exists.")

What I think is happening is that controls that are contained
in tables nested inside tables don't show in the Controls
collection, but can be "smoked" out using refraction.
Of course I don't want to resort to this, because it's
slow, and I have to run this process many times.

Any ideas? Or does anyone see something obvious that
I'm overlooking?
Nov 6 '06 #4

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

Similar topics

2
4990
by: Sam | last post by:
I have a custom control (MyTextBox - taken from Microsoft website) that implements the IPostBackDataHandler interface. It is added to the controls collection of a placeholder control during the Page Load of a main ASPX page. Now if we debug the MyTextBox, we find the order of events like so (during a Posback, of course): OnInit -> OnLoad -> LoadPostData. My question is why does the LoadPostData occur *after* the OnLoad instead of...
6
2233
by: dhnriverside | last post by:
Hi peeps, I'm trying to create some controls textboxes at runtime, based on the number of items in a IETreeView that are checked. That I can do, I've got a place holder and I can create the corrent number of controls. The problem is that they appear next to each other. I want to create the controls with some wording to the left of them (again, dynamically generated). Normally id use <table> with two colums, one for the
3
1828
by: vitaly.tomilov | last post by:
I'm using an ASP.NET form to display data from my database table, and I'm doing it in the following way: XmlDataDocument doc = new XmlDataDocument(mydataSet); XPathNavigator nav = doc.CreateNavigator(); XslTransform xslTran = new XslTransform(); xslTran.Load("Transform.XSL"); xslTran.Transform(nav, null, Response.Output, null); This produces me a nice HTML page with enhanced formatting specified
6
1954
by: Louise | last post by:
I use Visual Basic .NET Framework 1.1, Visual Studio. I have a Web page (aspx) referencing a control (ascx) that has a placeholder that is assigned one of 2 child controls through buttons. The ViewState of the second child control gets confused with the first child control - the first Text property in the 2nd child gets updated with the first Text property of the 1st child when the 2nd button is clicked after the 1st. For instance,...
8
2089
by: novus | last post by:
Hi, In ASP.net 2.0 I make a control which add the same controls dynamically. In the oninit event I add the controls to the controls collection. After that the loadviewstate event fills in the information on postbacks. The control can add and delete controls that is why on the postback I don't know how many controls there are. At the moment I am able to get the controls rendering but I have problems to save the count of the dynamic...
0
1144
by: MasterChief | last post by:
I have a content place holder that is showing the summary of a sale. Is there a way to create a button in the content place holder that the person can click on to print just what is in the content place holder?
1
2078
by: namewitheldbyrequest | last post by:
When I create a web form in VS 2005 I have a problem. I created a MasterPage with a ContentPlaceHolder object on it. Then I created a detail page that refrenced the Master Page. When I drag controls onto the ControlPlaceHolder on the Detail page, the controls end up at the upper left corner of the page and I have to drag them down onto the ControlPlaceHolder. The controls are coded in the HTML as position = absolute and I don't think...
8
2040
by: tagg3rx | last post by:
Hi All, I have created a panel as a place holder on an input interface and I want to be able to dynamicaly fill it with drop down lists, check boxes etc. So below I'll show you the two main pieces of this effort - the function that creates the dropdown list in question and the function that fires when the submit button is clicked. I've stepped through this and what I'm finding is that when the submit button is clicked the page posts back and...
2
2122
by: Raymond Du | last post by:
Hi, I need to find a way to place multiple textboxes and other controls dynamically on a web form, I tried to put a placeholder on a form then create and add controls dynamically into the place holder. It is not working, all controls added disappear after the postback. I tried to find a working sample on Internet with no lucks, some samples are able to keep the controls after the postback, but all values entered before the postback...
0
8057
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7998
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8470
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8329
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6010
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3959
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4022
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1580
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.