Finding a Dynamic control


Feb 17, 2005
Glen Mills, PA
Programming Experience
HI, I am adding many dynamic controls to a web form in the Initialization event. Later in the Page Load event I want to populate those controls. And on PostBacks I need to read those controls. I give each control a unique ID as it is added. How do I directly access the properties and methods of those controls? I can use nested “For Each” loops with testing to determine the controls ID but this is very messy. If I know the control ID I want to access, how do I get to its properties?
Here is the example. I have a Placeholder(ID = plc1) on a web form. In that place holder is a Panel, the panel contains a Table, the Table has a rows, Each row has cells, and within a cell I want to access a Drop Down list with an ID of “ddl1”. I want to add items to ddl1 and later read the selected text.
Below is my best guess. What should it really be?

Dim ctl as DropDownList = me.plc1.findcontrol(“ddl1”)

ctl.additems("First Item")

strResult = ctl.text

Top Bottom