Fetching all controls on a page ordered by their ID

Here's a simple to way to fetch all the controls on an ASP.NET page ordered by their ID's


    protected void Button1_Click(object sender, EventArgs e)


        var ctrl = from ctr in this.Controls.Cast<Control>().OrderBy(c => c.ID)

                   select ctr;     



Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim ctrl = _

     From ctr In Me.Controls.Cast(Of Control)().OrderBy(Function(c) c.ID) _

     Select ctr

End Sub

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

No comments: