I want to retrieve a textbox value in a button click event, but as soon as the button is clicked, the postback fires and the value is empty. I have tried to create the textbox in a (!isPostBack
) but that doesn't seem to work.
protected void Page_Load(object sender, EventArgs e)
{
Form.Controls.Add(t);
}
protected void Page_PreInit(object sender, EventArgs e)
{
predictionList = dc.getPredictions(Convert.ToInt32(Session["accountId"]));
fixtureList = dc.getFixtures();
t.CssClass = "panel panel-success table table-striped";
sortLists();
foreach (Fixture f in newList)
{
TableRow tr = new TableRow();
TableCell tc1= new TableCell();
TextBox tb1= new TextBox();
tb1.ID = "tb1";
tc1.Controls.Add(tb1);
tr.Cells.Add(tc1);
t.Rows.Add(tr);
}
}
Here I add the control, and here I want to process whatever is in the textbox:
protected void btSubmit_Click(object sender, EventArgs e)
{
foreach (TableRow r in t.Rows)
{
string textboxRead= ((TextBox)r.FindControl("tb1")).text;
int textboxInt = Convert.ToInt32(textboxRead);
}
}