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 236105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:19:06+00:00 2026-05-11T20:19:06+00:00

Does anyone have a function that will iterate through ever masterpage/sub masterpage that a

  • 0

Does anyone have a function that will iterate through ever masterpage/sub masterpage that a content form belongs to, and iterate through each control of said masterpage/sub masterpage?

The reason why i ask is that i’m building up an increasingly confusing stack of masterpages and am starting to “lose” controls – i.e. not being able to find them because they’re lost in the hierarchy.

Would be nice to have some function that will dump a tree of the hierarchy so i can locate my wayward controls.

  • 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-11T20:19:06+00:00Added an answer on May 11, 2026 at 8:19 pm

    You can do this pretty easily using a recursive method. If you want to be fancy you can even use extension methods that takes some delegates as parameters for greater flexibility.

    Implementing the method is as easy as dropping a new class in your App_Code folder:

    Public Module ControlParser
        Sub New()
        End Sub
        <System.Runtime.CompilerServices.Extension> _
        Public Sub ForEachRecursive(ByVal ctrl As Control, ByVal callback As Action(Of Control), ByVal onMethodEnter As Action, ByVal onMethodLeave As Action)
            onMethodEnter.Invoke()
            
            If ctrl Is Nothing Then
                Exit Sub
            End If
            
            callback(ctrl)
            
            For Each curCtrl As Control In ctrl.Controls
                ForEachRecursive(curCtrl, callback, onMethodEnter, onMethodLeave)
            Next
            
            onMethodLeave.Invoke()
        End Sub
    End Module
    

    Utilizing this from inside your page to walk through all controls and print them out in a hierarchical view could be accomplished like so:

    Private depth As Int32 = -1
    Private sbOutput As New StringBuilder()
    Private Const SPACES_PER_TAB As Int32 = 4
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Me.ForEachRecursive(PrintControl, Function() System.Math.Max(System.Threading.Interlocked.Increment(depth),depth - 1), Function() System.Math.Max(System.Threading.Interlocked.Decrement(depth),depth + 1))
        //Output is a panel on the page
        output.Controls.Add(New LiteralControl(sbOutput.ToString()))
    End Sub
    
    Public Sub PrintControl(ByVal c As Control)
        sbOutput.Append(GetTabs(depth) + c.ClientID & "<br />")
    End Sub
    
    Public Function GetTabs(ByVal tabs As Int32) As [String]
        Return If(tabs < 1, String.Empty, New [String]("*"c, tabs * SPACES_PER_TAB).Replace("*", "&nbsp;"))
    End Function
    

    I appologize if the code looks funny, but I coded this in C# and used a converter. However, I was able to dump the actual VB code into my App_Code directory and confirm that it worked.

    Hope this helps 🙂

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

Sidebar

Ask A Question

Stats

  • Questions 175k
  • Answers 175k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Memory leaks are probably the worst. If you manage to… May 12, 2026 at 3:01 pm
  • Editorial Team
    Editorial Team added an answer As luck would have it, I stumbled across this the… May 12, 2026 at 3:01 pm
  • Editorial Team
    Editorial Team added an answer Some of the pitfalls: You will not be able to… May 12, 2026 at 3:00 pm

Related Questions

I'm loading some HTML via Ajax with this format: <div id=div1> ... some content
I have a struct as follows, with a pointer to a function called length
... and thanks for reading... I'm still learning the ropes so please be forgiving...
I have a matrix class with the size determined by template parameters. template <unsigned

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.