473,385 Members | 1,893 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,385 software developers and data experts.

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.Page oCurrentPage = null;
System.Collections.IEnumerator oEn;

// Use context parameter to determine page
oEn = ((System.Web.UI.WebControls.WebControl)
context.Instance).Site.Container.Components.GetEnu merator();

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

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 1943
"James Doran" <ja*****@breathe.com> wrote in message
news:15**************************@posting.google.c om...
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.Page oCurrentPage = null;
System.Collections.IEnumerator oEn;

// Use context parameter to determine page
oEn = ((System.Web.UI.WebControls.WebControl)
context.Instance).Site.Container.Components.GetEnu merator();

// Get the page that the control is situated on...
oEn.MoveNext();
oCurrentPage = (System.Web.UI.Page)oEn.Current;
////////////////////////////////////////////////////////////////////////
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
johnwsaundersiii 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*************@TK2MSFTNGP10.phx.gbl...
"James Doran" <ja*****@breathe.com> wrote in message
news:15**************************@posting.google.c om...
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.Page oCurrentPage = null;
System.Collections.IEnumerator oEn;

// Use context parameter to determine page
oEn = ((System.Web.UI.WebControls.WebControl)
context.Instance).Site.Container.Components.GetEnu merator();
// Get the page that the control is situated on...
oEn.MoveNext();
oCurrentPage = (System.Web.UI.Page)oEn.Current;

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

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
johnwsaundersiii at hotmail

Nov 18 '05 #3

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

Similar topics

2
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...
0
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...
2
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...
4
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...
1
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
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...
7
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
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...
2
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...
7
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.