473,848 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Iterate every Page Page.Controls collection in a project at design-time

Hello,

I'd like to iterate through each Page of my ASP.NET project from
within a Custom web control and access the Page.Controls collection.

I've tried using Reflection on the web project assembly, but the
controls collection count was zero. While this method gives details
of the private controls in each page, I need access to actual
instances of the controls to interrogate their individual properties.

Next I tried from with a web custom control. Using a custom
UITypeEditor, I was able to access the page object in the EditValue
method of the type editor using the following code:

////////////////////////////////////////////////////////////////////////
System.Web.UI.P age oCurrentPage = null;
System.Collecti ons.IEnumerator oEn;

// Use context parameter to determine page
oEn = ((System.Web.UI .WebControls.We bControl)
context.Instanc e).Site.Contain er.Components.G etEnumerator();

// Get the page that the control is situated on...
oEn.MoveNext();
oCurrentPage = (System.Web.UI. Page)oEn.Curren t;
////////////////////////////////////////////////////////////////////////

This was a step in the right direction, as I was able to get access to
the controls collection. The only problem is that I can't access
other pages of the same project from within this control.

The only other thing I can think of is using ENVDTE to go through the
project files, but I don't think I would have the same amount of
control and would end up having to manually parse the ASPX files,
which would be very messy.

I would be most grateful if anyone has time to help.

Many thanks,

James
Nov 18 '05 #1
2 1962
"James Doran" <ja*****@breath e.com> wrote in message
news:15******** *************** ***@posting.goo gle.com...
Hello,

I'd like to iterate through each Page of my ASP.NET project from
within a Custom web control and access the Page.Controls collection.

I've tried using Reflection on the web project assembly, but the
controls collection count was zero. While this method gives details
of the private controls in each page, I need access to actual
instances of the controls to interrogate their individual properties.

Next I tried from with a web custom control. Using a custom
UITypeEditor, I was able to access the page object in the EditValue
method of the type editor using the following code:

//////////////////////////////////////////////////////////////////////// System.Web.UI.P age oCurrentPage = null;
System.Collecti ons.IEnumerator oEn;

// Use context parameter to determine page
oEn = ((System.Web.UI .WebControls.We bControl)
context.Instanc e).Site.Contain er.Components.G etEnumerator();

// Get the page that the control is situated on...
oEn.MoveNext();
oCurrentPage = (System.Web.UI. Page)oEn.Curren t;
////////////////////////////////////////////////////////////////////////
This was a step in the right direction, as I was able to get access to
the controls collection. The only problem is that I can't access
other pages of the same project from within this control.

The only other thing I can think of is using ENVDTE to go through the
project files, but I don't think I would have the same amount of
control and would end up having to manually parse the ASPX files,
which would be very messy.

I would be most grateful if anyone has time to help.


I think you really don't want to do this. How often do you expect your
iterate code to be called? Every time a page is added to the project?
Removed? Every time a control is added, removed or changed? That's a lot of
calls.

That's also assuming that you can find a way to do this at all. You would
have to use the VS.NET extension API (see "
Extending the Visual Studio Environment" in the VS.NET documentation) to
locate each file. Then, you'd somehow have to create a designer for each
page (I don't believe a designer can reference more than a single page) and
have that designer iterate through the controls for you.

Perhaps you should consider a different way of meeting the underlying
requirement.
--
John Saunders
johnwsaundersii i at hotmail
Nov 18 '05 #2
John,

Many thanks for your reply.

It sounds like quite a job, and like you say quite inefficient! I'll have a
look into the documentation you've suggested though.

Cheers,

James

"John Saunders" <jo************ **@notcoldmail. com> wrote in message
news:uQ******** *****@TK2MSFTNG P10.phx.gbl...
"James Doran" <ja*****@breath e.com> wrote in message
news:15******** *************** ***@posting.goo gle.com...
Hello,

I'd like to iterate through each Page of my ASP.NET project from
within a Custom web control and access the Page.Controls collection.

I've tried using Reflection on the web project assembly, but the
controls collection count was zero. While this method gives details
of the private controls in each page, I need access to actual
instances of the controls to interrogate their individual properties.

Next I tried from with a web custom control. Using a custom
UITypeEditor, I was able to access the page object in the EditValue
method of the type editor using the following code:

////////////////////////////////////////////////////////////////////////
System.Web.UI.P age oCurrentPage = null;
System.Collecti ons.IEnumerator oEn;

// Use context parameter to determine page
oEn = ((System.Web.UI .WebControls.We bControl)
context.Instanc e).Site.Contain er.Components.G etEnumerator();
// Get the page that the control is situated on...
oEn.MoveNext();
oCurrentPage = (System.Web.UI. Page)oEn.Curren t;

////////////////////////////////////////////////////////////////////////

This was a step in the right direction, as I was able to get access to
the controls collection. The only problem is that I can't access
other pages of the same project from within this control.

The only other thing I can think of is using ENVDTE to go through the
project files, but I don't think I would have the same amount of
control and would end up having to manually parse the ASPX files,
which would be very messy.

I would be most grateful if anyone has time to help.


I think you really don't want to do this. How often do you expect your
iterate code to be called? Every time a page is added to the project?
Removed? Every time a control is added, removed or changed? That's a lot

of calls.

That's also assuming that you can find a way to do this at all. You would
have to use the VS.NET extension API (see "
Extending the Visual Studio Environment" in the VS.NET documentation) to
locate each file. Then, you'd somehow have to create a designer for each
page (I don't believe a designer can reference more than a single page) and have that designer iterate through the controls for you.

Perhaps you should consider a different way of meeting the underlying
requirement.
--
John Saunders
johnwsaundersii i at hotmail

Nov 18 '05 #3

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

Similar topics

2
5363
by: Simon | last post by:
I've got a webform and many controls on it. I would like to iterate thru the control collection to get all the textboxes control to let me change the text property. Here is my code...for unknown reason, this loop iterates only 3 times! Help please! Thanks! Dim Control As Web.UI.Control Dim TextBox As System.Web.UI.WebControls.TextBox For Each Control In Controls If TypeOf (Control) Is System.Web.UI.WebControls.TextBox Then
0
2233
by: Frnak McKenney | last post by:
I'm running into problems with VisualStudio.NET2003 and Windows Forms inheritance. It _feels_ like a bug, but it could just as well be a misunderstanding on my part regarding how the VS Designer handles inheritance. Environment: OS Name Microsoft Windows 2000 Professional Version 5.0.2195 Service Pack 4 Build 2195 Microsoft Visual C# .NET
2
3682
by: JDavies | last post by:
Hi All I am dynamically Creating DropDownList boxes for a Survey form. These DropdownLists are added to Table Cells programatically. I tried to loop thru the controls on the form but it doesnt seem to work right, the loop appears below: for each cntl in page.controls(1).controls ddlId = cntl.Id
4
2504
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in the table. I know that I can dynamically add controls (eg a textbox) to the page controls collection of a web form in a server event which will then be rendered onto the form, as in the following snippet: System.Web.UI.WebControls.TextBox...
1
2108
by: Dan Sikorsky | last post by:
How do you recursively iterate thru each collection on each form on a web page and find each web control? -- Thank you kindly, Dan Sikorsky BAB, BScE, MSC
2
1948
by: Oleg | last post by:
Let's say I rendered a bunch of controls with the same name and different IDs. On postback, can I somehow iterate through these controls (checkboxes in this case, but could be dropdown controls in the future) and get their values and IDs with all this done in the code behind page? A small example would be appreciated. Thanks, Oleg
7
5052
by: Rich | last post by:
Hello, I have a form with 5 textboxes named txt0, txt1, txt2, txt3, tx4. In VB6 I could iterate through these with For i = 0 to 4 debug.print Me.controls("txt" & i).Name Next
8
1710
by: | last post by:
I'm looking for some design guidance on a collection of projects I'm working on. The project involves a bunch of websites constructed out of a collection of user controls. Different user populations with different access rights and "roles" will be visiting the site. I will be using ASP.NET 2.0's membership, roles, and profiles stuff to manage access. User controls need to be visible or not visible depending on user role. In some...
2
1958
by: Luqman | last post by:
I have a Ajax Tab Container on my Webform with One Panel and some Labels and Textboxes. I want to Iterate through all the textboxes and return their IDs. I tried every possibility I could but I was unable to retrieve their IDs. Here is my code, which returns nothing. Dim ctrl as new Control
7
2305
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using FindControl the only way to do it?
0
9893
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
11001
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10722
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10348
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
9500
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...
0
7069
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5919
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4544
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
2
4137
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.