Dynamically Created Textboxes not updating
<p>I'm creating textboxes in the Page_Load event and giving them values, however whenever I load the details I am getting the same output.  I always seem to get the first output I got, even on subsequent searches.</p>

<p>Here's what my code with the irrelevant information missing:</p>

<pre><code>Textbox txtName = New Textbox();
protected void Page_Load(object sender, EventArgs e)
{
    LoadData();
}

void LoadData()
{
    txtName.Text = DropDownList.SelectedValue;
    tableCell.Controls.Add(txtName);
}
</code></pre>

<p>If <code>DropDownList</code> has two values (e.g. "Item 1" and "Item 2") and has autopostback enabled, first time it will generate and show "Item 1" in the textbox (the default value for the DropDownList), but if this is changed and the autopostback fires, the textbox does not change.</p>

<p>I've tried getting around this by creating a new TextBox, overriding the "LoadPostData" function to prevent this from loading, which got around the issue there, but then I couldn't view the data afterwards.</p>

<p>Any idea how I could get around this?  I may be approaching this in the wrong way.</p>

<p>Edit: I've added another item to <code>DropDownList</code> that removes <code>TextBox</code>, so that it can be re-created again.  It seems to show the correct data when it is re-created after being removed, but if I'm attempting to just edit it, this isn't updating correctly.</p>

<p>Edit2: Here's the rest of the code for this page in case this helps at all.  The objects which I'm having issues with are SBUName and SBUComments, which are both TextBoxes.  The same issue is also happening for SBUClientDropdown but I believe the resolution will be similar:</p>

<pre><code>DBHandler DBHandler = new DBHandler();
List&lt;string&gt; clients = new List&lt;string&gt;();
List&lt;string&gt; clientGroups = new List&lt;string&gt;();
List&lt;string&gt; sbus = new List&lt;string&gt;();

// Objects for SBU changes
string previousSBU = "";
string previousSBUClient = "";
TextBox SBUName = new TextBox() { ID = "SBUName" };
TextBox SBUComments = new TextBox() { ID = "SBUComments" };
DropDownList SBUClientDropdown = new DropDownList();

protected void Page_Load(object sender, EventArgs e)
{
    clients = DBHandler.GetClients();
    clientGroups = DBHandler.GetClientGroups();

    if (!Page.IsPostBack)
    {
        foreach (string client in clients)
        {
            SBUClientList.Items.Add(GenerateItem(client));
            ClientList.Items.Add(GenerateItem(client));
        }

        foreach (string clientGroup in clientGroups)
            ClientGroupList.Items.Add(GenerateItem(clientGroup));
    }

    if ((SBUClientList.SelectedValue.ToString() != previousSBUClient) || (SBUList.SelectedValue.ToString() != previousSBU))
    {
        previousSBUClient = SBUClientList.SelectedValue.ToString();
        previousSBU = SBUList.SelectedValue.ToString();

        sbus = DBHandler.GetSBUs(SBUClientList.SelectedValue);
        SBUList.Items.Clear();
        foreach (string sbu in sbus)
            SBUList.Items.Add(GenerateItem(sbu));

        LoadSBU();
    }
}

void LoadSBU()
{
    if ((SBUClientList.SelectedValue.Trim().Length &gt; 0) &amp;&amp; (SBUList.SelectedValue.Trim().Length &gt; 0))
    {
        Entity thisSBU = DBHandler.GetSBUInformation(SBUClientList.SelectedValue, SBUList.SelectedValue);

        SBUTable.Rows.Add(GenerateHeaderRow("Client Name", "SBU Name", "Comments"));

        SBUClientDropdown.Items.Clear();
        foreach (string client in clients)
            SBUClientDropdown.Items.Add(GenerateItem(client));
        SBUClientDropdown.SelectedValue = SBUClientList.SelectedValue;
        SBUClientDropdown.SelectedIndex = SBUClientList.SelectedIndex;
        TableCell SBUClientCell = new TableCell();
        SBUClientCell.Controls.Add(SBUClientDropdown);


        SBUName.Text = thisSBU.sSBUName;
        TableCell SBUNameCell = new TableCell();
        SBUNameCell.Controls.Add(SBUName);


        SBUComments.Text = thisSBU.sSBUComments;
        TableCell SBUCommentsCell = new TableCell();
        SBUCommentsCell.Controls.Add(SBUComments);

        SBUTable.Rows.Add(GenerateRow(SBUClientCell, SBUNameCell, SBUCommentsCell));

        Button SBUSaveButton = new Button();
        SBUSaveButton.Click += new EventHandler(this.SBUSaveChanges);
        SBUSaveButton.Text = "Save SBU Changes";
        TableCell SBUButtonCell = new TableCell();
        SBUButtonCell.Controls.Add(SBUSaveButton);
        SBUButtonCell.ColumnSpan = 3;
        TableRow SBUFooter = GenerateRow(SBUButtonCell);
        SBUFooter.TableSection = TableRowSection.TableFooter;
        SBUTable.Rows.Add(SBUFooter);
    }
}

void ShowMessage(string message)
{
    OutputString.Text = "&lt;div class=\"message\"&gt;" + message + "&lt;/div&gt;";
}

ListItem GenerateItem(string input)
{
    ListItem output = new ListItem();
    output.Text = input;
    return output;
}

TableCell GenerateCell(string text)
{
    TableCell output = new TableCell();
    output.Text = text;
    return output;
}

TableRow GenerateRow(params TableCell[] cells)
{
    TableRow output = new TableRow();
    foreach (TableCell cell in cells)
        output.Cells.Add(cell);
    return output;
}

TableRow GenerateHeaderRow(params string[] columns)
{
    TableRow output = new TableRow();
    output.TableSection = TableRowSection.TableHeader;

    foreach (string column in columns)
    {
        TableCell thisCell = new TableCell();
        thisCell.Text = column;
        output.Cells.Add(thisCell);
    }

    return output;
}
</code></pre>
