Accessing a control dynamically added to a placeholder during an event
<p>I'm creating an ASP.NET control dynamically based on a value selected in a dropdown; for instance the field can be a textbox or a checkbox (for now), and then it gets added to a placeholder control.  However, I'm unsure how to retrieve the value - using the placeholder's <code>FindControl</code> method returns null although I'm specifying the ID when I create the control.</p>

<p>Here's my code:</p>

<pre><code>protected void ddlFields_SelectedIndexChanged(object sender, EventArgs e) {
    // this simply gives me back an object with some properties 
    // such as the type of field (e.g. text, boolean, number)
    var column = GetFieldDetailsByValue(ddlFields.SelectedValue);
    this.CreateInputControl(column.Type);  
}

private void CreateInputControl(string dataType) { 
    Control controlToAdd = null;

    switch (dataType) {
        case TYPE_STRING:
        case TYPE_NUMBER:
            controlToAdd = new TextBox();
            break;
        case TYPE_BOOL:
            controlToAdd = new CheckBox();
            break;      
    }

    if (controlToAdd != null) { 
        controlToAdd.ID = "ctlFieldValue";
        this.fieldsPlaceholder.Controls.Add(controlToAdd);
    }
}
</code></pre>

<p>I have a Button event which checks for the <code>ctlFieldValue</code> control to retrieve it's value, however it's always null.  How should I go about handling this?</p>
