Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:18:00+00:00 2026-06-14T22:18:00+00:00

How do I access asp.net controls that are nested multiple levels in a page

  • 0

How do I access asp.net controls that are nested multiple levels in a page from a custom validator?

Specifically, I am generating dropdownlists that are inside a placeholder, which is inside a repeater, which is inside of another repeater, which is inside of another placeholder.

I need to access the selected values of all of the drop down boxes to compare to one another.

My current solution is to loop through all of the controls inside each control, until I get down deep enough to access the dropdownlist’s:

    For Each g As Control In sender.Parent.Controls
        If g.GetType().ToString.Equals("System.Web.UI.WebControls.Repeater") Then
            For Each k As Control In g.Controls
                If k.GetType().ToString.Equals("System.Web.UI.WebControls.RepeaterItem") Then
                    For Each l As Control In k.Controls
                        If l.GetType().ToString.Equals("System.Web.UI.WebControls.Repeater") Then
                            For Each p As Control In l.Controls
                                If p.GetType().ToString.Equals("System.Web.UI.WebControls.RepeaterItem") Then
                                    For Each n As Control In p.Controls
                                        If n.GetType().ToString.Equals("System.Web.UI.WebControls.PlaceHolder") Then
                                            For Each c As Control In n.Controls
                                                If c.GetType().ToString.Equals("System.Web.UI.WebControls.DropDownList") Then

                                                'Add the dropdownlist to an array so that I can use it after all drop down lists have been added for validation.

This seems like an entire waste of resources. Is there a better way to access these controls from the custom validator?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:18:01+00:00Added an answer on June 14, 2026 at 10:18 pm

    I believe you can use $ to concatenate container names to access a nested control; something like this:

    ControlToValidate="panel1$usercontrol1$otherusercontrol$textbox1"
    

    This does result in an internal FindControl() call to be performed by the validator which is somewhat expensive so you should use this approach sparingly.

    In general, it’s not a very good idea to access deeply nested controls inside other containers. You should treat these controls as private members of a page / control and not access them this way. Only use the above approach if you really, really must.

    Edit: this may not be the perfect solution but I’d do it this way. Create a new DropDownListX control (derives from DropDownList) that grabs the page and checks if the page implements a new custom interface that you create. This interface can be used to register a control with the page and then your validator can go through this list and validate each registered control. Something like:

    interface IValidationProvider
    {
        void RegisterForValidation ( Control oCtrl );
    }
    

    Your page should implement this interface. Then in your new DropDownListX control:

    protected override void OnLoad ( EventArgs e )
    {
        IValidationProvider oPage = Page as IValidationProvider;
    
        if ( oPage != null )
            oPage.RegisterForValidation ( this );
    }
    

    Then in the page, when validation happens, you can go through the list of controls in the validation list and validate them one by one. Your custom validator won’t have a single ControlToValidate control name but that seems appropriate for you, since you have 1 validator that validates multiple controls inside nested repeaters.

    This solution gives you the ability to completely skip your current deep loop – if you have a control that needs validation, it’ll register itself, otherwise the list in the page will be empty and nothing needs to be checked. This also avoids doing string comparisons for control names since controls don’t need to be searched – they register themselves when they need to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to access the raw HTML code that my ASP.NET System.Web.UI.Page is about
How can I access Microsoft Outlook contacts using ASP.NET? Are there any controls that
Should I access the asp.net membership class from the controller and pass the results
Is there any way to access my asp.net dev server (launched from visual studio)
I have an ASP.NET web service that I can access via a windows program
I have an asp.net page with a multiview control nested within another multiview control.
On my C# asp.net webform I have a search page that has roughly 20
I'm adding a dynamically built set of checkboxes to an asp.net page from the
On postback : How can I access ASP.NET controls in my code-behind file, which
I have an ASP.NET web app that uses a single page, but makes some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.