This tutorial will show you how to Locate Controls by ID using ASP.NET 2.0 and VB.NET

Every container control on the page, and the page itself, has a Controls collection that you can use to get to individual controls or loop through the controls collection. On the other way, the ASP.NET page framework provides your applications with automatic control ID resolution through the INamingContainer interface, which generates a naming container for each class that implements it. A naming container defines a new ID namespace within an ASP.NET Web page control hierarchy. A naming container then allows the page framework to generate a value for the UniqueID property of each Control object generated within that namespace. The UniqueID property is different from the ID property that you declare in that it is the fully qualified identifier for a control.

This tutorial only using the default namespace. But Label control will be bound to a data source and the Repeater control iterates , in this tutorial. So, you will need to import the System.Text,

We use the Button1_Click event to loop through all textbox controls in this page. And we use the Button2_Click to find individual controls and print out those controls UniqueID.

The front end .aspx page looks something like this:

The flow for the code behind page is as follows.

Download Source Files