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

Programmaticly enumerate all controls and properties on an ASP.NET page

J
I'm trying to make a list of certain properties of all the controls on an
ASP.NET page. Does anyone know of an easy way to do this? I've tried to
do it a couple of different ways but I'm not getting the hang of it I'm
afraid. Right now I'm parsing text file but that's a pain, not very
elegant, and I'm not sure it'll give me all the info I need. Right now
I'm using VB.Net as the back end but I'll take C#.Net code in a pinch. :)

Tanx in advance,

J
Nov 21 '05 #1
3 1641
Could you, for instance, use the Page.Controls collection and recursively
walk through each control?

"J" <Me@here.com> wrote in message
news:pa****************************@here.com...
I'm trying to make a list of certain properties of all the controls on an
ASP.NET page. Does anyone know of an easy way to do this? I've tried to
do it a couple of different ways but I'm not getting the hang of it I'm
afraid. Right now I'm parsing text file but that's a pain, not very
elegant, and I'm not sure it'll give me all the info I need. Right now
I'm using VB.Net as the back end but I'll take C#.Net code in a pinch. :)

Tanx in advance,

J

Nov 21 '05 #2
J
Hi Peter,

I've tried something similar but it seems more complicated than that. If
I look through the list of objects on the property list on the right hand
side I see six objects (including the web form). When I use
page.controls.count I get 3. Those objects are 'ctl0', 'form1', and
'ctl1' respectively. It looks like I can access the controls on the form
through 'form1'. Page.Controls(1).Controls.Count yields the correct
number. I suspect that means that I first have to iterate through the
page controls and find out which one is the form. Is that always the way
it works? If not then this could get messy really quickly. :(

J

On Sun, 20 Nov 2005 21:26:32 -0800, Peter Rilling wrote:
Could you, for instance, use the Page.Controls collection and recursively
walk through each control?

"J" <Me@here.com> wrote in message
news:pa****************************@here.com...
I'm trying to make a list of certain properties of all the controls on an
ASP.NET page. Does anyone know of an easy way to do this? I've tried to
do it a couple of different ways but I'm not getting the hang of it I'm
afraid. Right now I'm parsing text file but that's a pain, not very
elegant, and I'm not sure it'll give me all the info I need. Right now
I'm using VB.Net as the back end but I'll take C#.Net code in a pinch. :)

Tanx in advance,

J


Nov 21 '05 #3
J
SWEET!

Here's what I did.

Private Sub CtrlList(ByVal ctrlCol As ControlCollection)
Dim ctrl As Control
For Each ctrl In ctrlCol
If ctrl.HasControls Then
CtrlList(ctrl.Controls)
Else
System.Diagnostics.Debug.WriteLine(ctrl.ClientID)
End If
Next
End Sub

I love recursion. ;)

J

On Mon, 21 Nov 2005 00:56:16 -0500, J wrote:
Hi Peter,

I've tried something similar but it seems more complicated than that. If
I look through the list of objects on the property list on the right hand
side I see six objects (including the web form). When I use
page.controls.count I get 3. Those objects are 'ctl0', 'form1', and
'ctl1' respectively. It looks like I can access the controls on the form
through 'form1'. Page.Controls(1).Controls.Count yields the correct
number. I suspect that means that I first have to iterate through the
page controls and find out which one is the form. Is that always the way
it works? If not then this could get messy really quickly. :(

J

On Sun, 20 Nov 2005 21:26:32 -0800, Peter Rilling wrote:
Could you, for instance, use the Page.Controls collection and recursively
walk through each control?

"J" <Me@here.com> wrote in message
news:pa****************************@here.com...
I'm trying to make a list of certain properties of all the controls on an
ASP.NET page. Does anyone know of an easy way to do this? I've tried to
do it a couple of different ways but I'm not getting the hang of it I'm
afraid. Right now I'm parsing text file but that's a pain, not very
elegant, and I'm not sure it'll give me all the info I need. Right now
I'm using VB.Net as the back end but I'll take C#.Net code in a pinch. :)

Tanx in advance,

J


Nov 21 '05 #4

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

Similar topics

7
by: localhost | last post by:
What is the best and/or fastest way to enumerate attributes of an HTML control? In my page template, I have: <body id="myBody" bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0"...
2
by: Rubble | last post by:
Hello, Ive searched all over the net trying to find an answer to this...so anybody with some expertise in this area would be greatly appreciated. Background: I have a webform that loads a...
2
by: ScottOnes | last post by:
Hi I have a placeholder that has multiple controls that need to be loaded and rendered to the user based on some user selections. I have to loop through the choices that the user makes and then...
2
by: Urs Eichmann | last post by:
Hello, I want to define a MasterPage which already has some asp:Textbox and other controls defined inside a ContentPlaceHolder. The idea is that the user of the master page just changes two or...
5
by: HL | last post by:
Hi, I need to enumerate windows and find the sum of the rect of all the windows of a specific application. In C++, I use the APIs - 'EnumWindows , GetWindowRect and UnionRect to accomplish the...
0
by: Jeremy Chapman | last post by:
I have included below virtually all the code to a control I'm trying to build. My issue is that an array list property in my control does not get persisted properly to the aspx page code in design...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
0
by: bcanter | last post by:
I found a file on the web that will allow you to enumerate groups but it was an .hta and the top level admins won't allow this. I need to give managers access to the groups so that when a new user is...
4
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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?
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...

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.