Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-09-20
3
Medium Priority
?
220 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 1000 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 1000 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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

636 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