I create a DIV that runs on the server and then dynamically create and add TextBox controls to that DIV. Later when I try to read the Text property of each TextBox in DIV I cannot get the controls...
How do I accomplish this?
DIV that runs at server...
<div id="divBonusPercents" runat="server"></div>
Dynamically Add Textboxes based on some condition...
foreach (ListItem item in lbTeamsEOM.Items)
if (item.Selected)
{
// add controls for team bonus %
TextBox tbPercent = new TextBox();
tbPercent.Text = "15%";
tbPercent.ID = "tbPercent" + item.Value;
divBonusPercents.Controls.Add(tbPercent);
}
Get the value for each TextBox in the DIV
List<string> lBonusPercent = new List<string>();
foreach (Control c in divBonusPercents.Controls)
if (c.GetType() == typeof(TextBox))
lBonusPercent.Add(((TextBox)c).Text);
Previous posters are correct in that you won't be able to access the
Textproperty of the TextBoxes unless they're created early enough in the page life cycle.However, the actual posted Form elements should still be there in the HTTP Request.
Request.Form[**TextBoxObjectHere**.UniqueID]should return whatever text was in a textbox on form post.