Question

I have an old web form that is quite extensive with a lot of controls on it. I'd like to make a list of all the controls on it and what types they are, but I was hoping Visual Studio would have something similar to SQL Server's INFORMATION_SCHEMA table or sys.*. Does anyone know if Visual Studio has a similar feature? It doesn't have to be a table - it could be a comma separated list, etc. Web searches have turned up ways to pull controls via code, but I was really wanting something quicker.

EDIT:

So it seems the general consensus is that this type of functionality doesn't exist in Visual Studio and getting those controls must be done programmatically. @servergta 's answer seems to be the easiest alternative with the one modification of moving the initial declaration of the StringBuilder outside of the method to keep it from re-setting every time it calls itself.

Thanks to everyone who gave an answer!

Was it helpful?

Solution

Sorry for the other answer, haven't tested it.

Here is a method that I've tested and worked:

private string getctl(Control master)
    {
        StringBuilder sb = new StringBuilder();
        foreach (Control child in master.Controls)
        {
            sb.AppendFormat("| {0} - {1}", child.ClientID.ToString(), child.GetType().ToString());
            if (child.HasControls())
            {
                sb.Append(getctl(child));
            }
        }
        return sb.ToString();
    }

you could run it like:

string controls = getctl(this.Page);

OTHER TIPS

Not in the general Visual Studio tools. If it's a web-project, and not a web-site, you can inspect the designer.cs file that accompanies the webform, and is relatively uniform and could be inspected by machine/script. However, if you just need a visual list, you can use the class browser in Solution Explorer.

enter image description here

However, the control tree is parsed and generated at run-time, so it won't be a definitive list. (Data bound controls, for example). To get a definitive list, you could, at runtime, use Trace functionality which will give you the control tree outputted to an HTML table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top