473,586 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find user controls?

How to find all user controls (ascx) loaded on a Page?
Nov 18 '05 #1
6 8890
This is one way:

' Visual Basic .NET
Dim form As HtmlForm = Me.FindControl (<form id>)
For Each ctl2 As Control In form.Controls
If (TypeOf ctl2 Is UserControl) Then
Response.Write( ctl2.ID)
End If
Next

"TomislaW" <to*********@ho tmail.com> wrote in message
news:OE******** ******@TK2MSFTN GP09.phx.gbl...
How to find all user controls (ascx) loaded on a Page?

Nov 18 '05 #2
You'd probably need to recurse that algorithm down each control's Controls
collection (reguardless of whether or not it's a UserControl)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Shiva" <sh******@onlin e.excite.com> wrote in message
news:u1******** ******@TK2MSFTN GP10.phx.gbl...
This is one way:

' Visual Basic .NET
Dim form As HtmlForm = Me.FindControl (<form id>)
For Each ctl2 As Control In form.Controls
If (TypeOf ctl2 Is UserControl) Then
Response.Write( ctl2.ID)
End If
Next

"TomislaW" <to*********@ho tmail.com> wrote in message
news:OE******** ******@TK2MSFTN GP09.phx.gbl...
How to find all user controls (ascx) loaded on a Page?

Nov 18 '05 #3
Hello Shiva,

Or, even easier...

C#:
foreach (UserControl uc in this.Page.Contr ols)
{
// do something
}

VB.NET
For Each uc As UserControl in Me.Page.Control s
' do something
Next

--
Matt Berther
http://www.mattberther.com
This is one way:

' Visual Basic .NET
Dim form As HtmlForm = Me.FindControl (<form id>)
For Each ctl2 As Control In form.Controls
If (TypeOf ctl2 Is UserControl) Then
Response.Write( ctl2.ID)
End If
Next
"TomislaW" <to*********@ho tmail.com> wrote in message
news:OE******** ******@TK2MSFTN GP09.phx.gbl...
How to find all user controls (ascx) loaded on a Page?

Nov 18 '05 #4
some of user controls are inside other user controls or panels etc.
so I did this with recursion.

"Matt Berther" <mb******@hotma il.com> wrote in message
news:uG******** ******@TK2MSFTN GP15.phx.gbl...
Hello Shiva,

Or, even easier...

C#:
foreach (UserControl uc in this.Page.Contr ols)
{
// do something
}

VB.NET
For Each uc As UserControl in Me.Page.Control s
' do something
Next

--
Matt Berther
http://www.mattberther.com
This is one way:

' Visual Basic .NET
Dim form As HtmlForm = Me.FindControl (<form id>)
For Each ctl2 As Control In form.Controls
If (TypeOf ctl2 Is UserControl) Then
Response.Write( ctl2.ID)
End If
Next
"TomislaW" <to*********@ho tmail.com> wrote in message
news:OE******** ******@TK2MSFTN GP09.phx.gbl...
How to find all user controls (ascx) loaded on a Page?


Nov 18 '05 #5
Hi Matt,
Or, even easier...

C#:
foreach (UserControl uc in this.Page.Contr ols)
{
// do something
}
Did you try this out? It won't work. Why? Because the User Controls are in
the WebForm, which is in the Page. You have to loop through the Form's
Controls Collection, not the Page's.

And what if the Control is nested inside another Control? The Controls
Collection of a Control doesn't contain the nested Controls. They are in the
Controls Collections of the Controls they immediately reside in.

The only way to truly find a Control whose location is not exactly known is
to use a recursive function that checks all Controls inside a given
Control's Controls Collection, and then calls itself for each Control in
that Collection. And start from the Form, not the Page, unless you expect a
given Control to be outside the form.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Matt Berther" <mb******@hotma il.com> wrote in message
news:uG******** ******@TK2MSFTN GP15.phx.gbl... Hello Shiva,

Or, even easier...

C#:
foreach (UserControl uc in this.Page.Contr ols)
{
// do something
}

VB.NET
For Each uc As UserControl in Me.Page.Control s
' do something
Next

--
Matt Berther
http://www.mattberther.com
This is one way:

' Visual Basic .NET
Dim form As HtmlForm = Me.FindControl (<form id>)
For Each ctl2 As Control In form.Controls
If (TypeOf ctl2 Is UserControl) Then
Response.Write( ctl2.ID)
End If
Next
"TomislaW" <to*********@ho tmail.com> wrote in message
news:OE******** ******@TK2MSFTN GP09.phx.gbl...
How to find all user controls (ascx) loaded on a Page?


Nov 18 '05 #6
Hello Kevin,

Of course, you're right regarding the WebForm portion.

The whole point of my response was to show that you dont have to do a loop
on Control and type check it for UserControl. You can do the foreach directly
on the UserControl type.

--
Matt Berther
http://www.mattberther.com
Hi Matt,
Or, even easier...

C#:
foreach (UserControl uc in this.Page.Contr ols)
{
// do something
}

Did you try this out? It won't work. Why? Because the User Controls
are in the WebForm, which is in the Page. You have to loop through the
Form's Controls Collection, not the Page's.

And what if the Control is nested inside another Control? The Controls
Collection of a Control doesn't contain the nested Controls. They are
in the Controls Collections of the Controls they immediately reside
in.

The only way to truly find a Control whose location is not exactly
known is to use a recursive function that checks all Controls inside a
given Control's Controls Collection, and then calls itself for each
Control in that Collection. And start from the Form, not the Page,
unless you expect a given Control to be outside the form.

"Matt Berther" <mb******@hotma il.com> wrote in message
news:uG******** ******@TK2MSFTN GP15.phx.gbl...
Hello Shiva,

Or, even easier...

C#:
foreach (UserControl uc in this.Page.Contr ols)
{
// do something
}
VB.NET
For Each uc As UserControl in Me.Page.Control s
' do something
Next
--
Matt Berther
http://www.mattberther.com
This is one way:

' Visual Basic .NET
Dim form As HtmlForm = Me.FindControl (<form id>)
For Each ctl2 As Control In form.Controls
If (TypeOf ctl2 Is UserControl) Then
Response.Write( ctl2.ID)
End If
Next
"TomislaW" <to*********@ho tmail.com> wrote in message
news:OE******** ******@TK2MSFTN GP09.phx.gbl...
How to find all user controls (ascx) loaded on a Page?

Nov 18 '05 #7

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

Similar topics

3
1747
by: David | last post by:
Hi, I have a page that will need to dynamically use 4 different user controls based on a Query String passed to it. Currently I have the @Register for each control and the <tagprefix: tagname> in a case statement depending on the quesry string. However, when the page is loaded, all 4 user controls seem to be compiled and instantiated when...
5
524
by: john | last post by:
I searched http://www.sellsbrothers.com. and could not find anything about this subject. How do I make C# User Controls Visible to Visual Basic 6.0 Applications? Thanks, John
4
1442
by: Dot net work | last post by:
If I have got 2 web user controls on my aspx form, and one web user control has got some validator controls on it, what I find is that if I enter in some "bad data" in to some text boxes on the first web user control, then click on a link button on the second web user control to leave the aspx form, it won't let me - the validators run on the...
7
1288
by: Mr Newbie | last post by:
Hi There, Here I am messing about with User Controls and I seem to have a conundrum on my hands which I'm sure you chaps will unravel for me in the blink of an eye.
1
1615
by: Philippe Meunier | last post by:
Ok, I already asked a question similar to this one but didn't found any answer ! I've a solution with 2 projects in it. One of the project contains Usercontrols and Inherited Controls. I work actively on both project, changing the usercontrols and the second project (forms that uses the usercontrols). When I build my solutuion, my user...
4
1245
by: Michael Turner | last post by:
Hi I have just added an existing project containing user controls into another solutions now they dont appear in 'my user controls' any idea why this is? I have tried building the solution. Thanks, Mike.
1
1550
by: randy1200 | last post by:
In Visual Studio 2003, I could create a new user control such as panel1. The name panel1 would appear in the toolbox under "My User Controls." I could drag this panel1 from the toolbox onto another panel or dialog box. This worked great. In Visual Studio 2005, I can still create a new user control such as panel1. The problem is I can't...
0
2155
by: mschep | last post by:
Hi, I built an assembly with a set of user controls. This can be done with the Visual Studio 2005 Deployment Project: building and merging for example all your aspx and ascx in one dll (lets say BunchOfUserControls.dll) Doing so it's possible to resuse user controls in other web projects without transferring the ascx files. Just the dll....
2
1477
by: tbh | last post by:
hi, hope this cross-post is OK. it's unclear to me whether this question belongs more under vstudio or dotnet... i'm using VS2005 pro and am one co-developer of a web solution that is getting to be at least medium sized. (about 60k lines of C# in the solution itself and perhaps another 20k lines in libraries we've developed.) finding...
0
7912
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...
0
7839
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...
0
8202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
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...
0
6614
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...
1
5710
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...
0
5390
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2345
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 we have to send another system

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.