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

  • SEARCH
  • Home
  • 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 4601930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:54:11+00:00 2026-05-21T23:54:11+00:00

i have 6 textboxes which i want to iterate. they are however in a

  • 0

i have 6 textboxes which i want to iterate.
they are however in a TD in a TR in a TABLE in a PANEL etc.

the only way i’ve figured out to iterate them is in this way:

this.Controls[0].Controls[3].Controls[7].Controls

that’s not only errorprone, but also hard to come up with.

but this.FindControl (to find one by name) doesn’t work either, does findcontrol also only search in the direct child, and not the whole hierarchie?

so basicly what i’m looking for is to iterate ALL controls in the page, no matter in which level of the hierarchie, to check if it’s a textbox.

Is there a way to do that?

EDIT: i don’t want to find them by their name (they are server controls so i could do that) because i would have to modify that code every time i add a textbox. By iterating the form i would not have to do that.

  • 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-05-21T23:54:11+00:00Added an answer on May 21, 2026 at 11:54 pm

    FindControl searches the hierarchy but it doesn’t go into controls that are an INamingContainer

    Any control that implements this interface creates a new namespace in which all child control ID attributes are guaranteed to be unique within an entire application. The marker provided by this interface allows unique naming of the dynamically generated server control instances within the Web server controls that support data binding. These controls include the Repeater, DataGrid, DataList, CheckBoxList, ChangePassword, LoginView, Menu, SiteMapNodeItem, and RadioButtonList controls.

    Basically it defines a boundary to avoid naming collisions. Consider how hard it’d be if all your control IDs really had to be unique.

    Note this information is also in the FindControl remarks. Tip: Always read the remarks.

    The FindControl method can be used to access a control whose ID is not available at design time. The method searches only the page’s immediate, or top-level, container; it does not recursively search for controls in naming containers contained on the page. To access controls in a subordinate naming container, call the FindControl method of that container.

    By doing so you could navigate to the control you want going through only the naming containers & calling FindControl at each level i.e. FindControl(“SomeNamingContainer”).FindControl(“AChildContainer”)

    That’s not necessarily practical, and depending on what you’re doing you really just need to get All TextBoxes.

    IEnumerable<TextBox> TextBoxes(ControlCollection ctrls)
    {
        var texts = ctrls.OfType<TextBox>();
        var children = ctrls.SelectMany(c => TextBoxes(c.Controls));
        return texts.Union(children);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple textboxes which I want them to perform the same thing upon
I have grid with some textboxes and an image which goes out of grid
I have two textboxes which uses the same class (they both need to be
I have some textboxes which I want to hide and then show on focus
Say I have textboxes, dropdownlists and submit buttons. They are all inline-elements. Which means
I have two textboxes that I want to even out. By even out, I
I have dynamically created textboxes, and I want each of them to be able
I have a WPF TextBox in which I want to allow autocompleting user names
I have an asp.net TextBox in which I want to check if the text
I currently have 4 textboxes which will be used to store an ip address.

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.