Steven Zack
Steven Zack

Reputation: 5114

how to select all controls in .net/c# like $('*') in jQuery?

Just wondering if there is a way to select all controls/items in asp.net/c# like $('*') performed in jQuery

Upvotes: 0

Views: 182

Answers (1)

Magnus
Magnus

Reputation: 46997

var allCtrls = GetChildren(Page);

protected IEnumerable<Control> GetChildren(Control parent)
{   
    foreach (Control ctrl in parent.Controls)
    {
        yield return ctrl;
        foreach (Control ctrl2 in GetChildren(ctrl))
            yield return ctrl2;
    }
}

Upvotes: 1

Related Questions