locked
how to get the list of all controls used in web form RRS feed

  • Question

  • User1754399827 posted
    hi i have a web page with some contorls like table, text box, label, panel etc. when my web page opens i want to know all the controls palced in the web page and their name/id. can any body tell me how to get the control details. thanks durga
    Monday, February 14, 2005 1:31 AM

All replies

  • User-1926422822 posted
    Every control has a Controls property that returns all the child controls. You can access all the controls on a page by iterating over the Page.Controls property and then these controls' child controls and so on.
    Monday, February 14, 2005 3:59 AM
  • User1146730029 posted
    Hopefully you are using VS, as I do not know how to do this in Web Matrix. Go to View -> Class view. In the toolbar that opens, navigate to your page. You will find a list of all the asp.net controls there. You can select them all and copy their id's from here. I do not know if you can also get what controls they are, but at least you can get theit id's.
    Monday, February 14, 2005 4:10 AM
  • User240536124 posted

    I know, old question. But I'm going to leave this here since it comes up in searches:

    Gets a comma separated string of all the control IDs on a web form:

    protected void FindControls()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            
            // form1.Controls
            foreach (Control c in form1.Controls) //Page.Controls
            {
                String txtId = string.Empty;
                if (c.GetType().Namespace == "System.Web.UI.WebControls")
                { 
                    txtId = c.ID;
                    sb.Append(txtId + ", ");                
                }
            }
    
            string cntrlList = sb.ToString();
        }

    Saturday, January 2, 2021 2:54 PM