Solved

Web .NET Getting a list of page controls from the server side

Posted on 2011-09-20
3
209 Views
Last Modified: 2012-05-12
In my web page, there is a list of controls that belong to the same class.  How can I get a list/IEnumerable of them from the server side?
0
Comment
Question by:Mare22
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 250 total points
Comment Utility
Hi,
You can get the list of controls using Page.Controls property. You can collect all the controls with your class using their CssClass Property.

Regards,
Ram
0
 
LVL 25

Assisted Solution

by:Luis Pérez
Luis Pérez earned 250 total points
Comment Utility
You can do a recursive function, because you can start in Page.Controls, but don't forget that a control can contain another controls:

As you didn't tell what server language you're using, I'll write in VB. If you prefer C#, please telll me and I'll translate.

'Declare list at page-level
Private m_Controls As List(Of Control) = New List(Of Control)

Private Sub CheckControls(ByVal col As ControlCollection)
    For Each c As Control In col
        'Check if c is suitable to be in your m_Controls List
        'I don't know what you wanted to say with "belong to the same class". If you were trying
        'to say that the controls have the same style class, you can check the CssClass property.
        'If you were talking about the controls base class, check c.GetType.ToString

        'Once you have checked for this concrete control (c), look for its subcontrols (if available)...
        Call CheckControls(c.Controls)
    Next
End Sub

Hope that helps.
0
 
LVL 25

Expert Comment

by:Luis Pérez
Comment Utility
Oh, I forgot that in Page_Load you must call for the first time to CheckControls:

Page_Load:
Call CheckControls(Me.Controls)

HTH
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now