asp.net call textbox[i] from textbox array created by hand before
My problem is: There is a button on web-form. It creates 5 textBoxes.
Then, there is another button on the same web-form. It gets values from
created textBoxes and make something:
protected void Page_Load(object sender, EventArgs e) { }
TextBox[] textbox;
protected void Button1_Click(object sender, EventArgs e)
{
textbox = new TextBox[5];
for (int i = 0; i < 5; i++)
{
textbox[i] = new TextBox();
textbox[i].ID = "textbox[" + i + "]";
PlaceHolder1.Controls.Add(textbox[i]);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string str = "";
for (int i = 0; i < 5; i++)
{
str += textbox[i].Text;
}
Label1.Text = str;
}
The error is in Button2_Click at textbox[i] is null. I understand why it
is happened, but I don't understand how can I solve this problem.
No comments:
Post a Comment