Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Programmaticly enumerate all controls and properties on an ASP.NET page

Reply
Thread Tools

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

 
 
J
Guest
Posts: n/a
 
      11-21-2005
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


 
Reply With Quote
 
 
 
 
Peter Rilling
Guest
Posts: n/a
 
      11-21-2005
Could you, for instance, use the Page.Controls collection and recursively
walk through each control?

"J" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
J
Guest
Posts: n/a
 
      11-21-2005
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" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
>> 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
>>
>>


 
Reply With Quote
 
J
Guest
Posts: n/a
 
      11-21-2005
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" <(E-Mail Removed)> wrote in message
>> news(E-Mail Removed)...
>>> 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
>>>
>>>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to upload files programmaticly mp33487@hotmail.com ASP .Net 0 05-19-2008 02:22 PM
IE Can't Enumerate User-Added Window Properties with for..in gyrm Javascript 0 11-26-2007 01:41 AM
How would I enumerate all the scripts available to a web page? Angus Javascript 10 04-16-2007 04:15 PM
Programmaticly load a custom UserControl with in a custom class which implements an ITemplate LaptopHeaven ASP .Net 0 10-05-2006 12:36 PM
How to enumerate all properties of the object and output them? GS ASP .Net 1 01-09-2006 05:04 PM



Advertisments