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.
Best Answer
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:
Utilizing this from inside your page to walk through all controls and print them out in a hierarchical view could be accomplished like so:
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 :)