473,770 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1674
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.c ount 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.Coun t 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 ControlCollecti on)
Dim ctrl As Control
For Each ctrl In ctrlCol
If ctrl.HasControl s Then
CtrlList(ctrl.C ontrols)
Else
System.Diagnost ics.Debug.Write Line(ctrl.Clien tID)
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.c ount 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.Coun t 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
4547
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" MS_POSITIONING="GridLayout" class="Body" runat="server"> And in my code-behind I want to look for the leftMargin
2
1348
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 datagrid. This datagrid has a button in a column that loads another datagrid(user control) when clicked. This new grid also has a column with a button that loads another user control. So, there could be 3 user controls on this form if all the
2
1431
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 load the controls. I am doing this in the protected override void Render(HtmlTextWriter writer) method. protected override void Render(HtmlTextWriter writer) { foreach (Selection in UsersSelection) {
2
1465
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 three properties of these "predefined" controls and has everything right in place. I realize I could program an ASCX or Webcontrol instead and let the users put that on the page themselves. But I would prefer if it was already predefined in the...
5
6971
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 same. How to perform the above in c#? Is PInvoke the only way to do it or Is there some inherent c# way?
0
3267
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 time. If I type the code in the aspx manually it does get parsed correctly though. This is an example of the aspx code that gets parsed correctly. For some reason, if I changed update the Tab property of the control through the GUI at design...
6
11081
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 how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of placeholder controls, and b) programmatically setting custom properties on those dynamically spawned...
0
2507
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 created they can tell me who they want their account to be modeled after. The html app works great as a .hta file but when it is saved as a web page it won't list the members of any groups. I get an error on line 182: "ActiveX component can't create...
4
51672
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 controls need to be dynamically loaded according to user input. This simple example can be further extended to dynamically load custom web user controls. Background Please familiarize yourself with the ASP.NET Page Life Cycle. It is crucial to...
0
9595
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
10232
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...
0
10059
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...
1
10008
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,...
1
7420
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
6682
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
5313
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...
1
3974
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
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.