Solved

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

Posted on 2011-09-20
3
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 250 total points
ID: 36571807
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
ID: 36572320
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
ID: 36572387
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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This video teaches users how to migrate an existing Wordpress website to a new domain.

705 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