Either you are getting Panel Object value as null or textbox Object value as null.
REASON 1:
Error line must be:
strValue +=
tb.Text + "\n";
Issue1 to me looks at:
strValue += tb.Text + "\n";
Looks like you are getting
"null"
for tb value here:
TextBox tb = pnl.FindControl(boxName) as TextBox;
Reason:
string boxName = "TextBoxID" + (i + 1).ToString();
REASON 2:
Error line must be:
TextBox tb =
pnl.FindControl(boxName) as TextBox;
If pnl value is null, then this line would throw an error.
Issue2 to me looks at:
TextBox tb = pnl.FindControl(boxName) as TextBox;
Looks like you are getting
"null"
for pnl value here:
Panel pnl = (Panel)Page.FindControl("Panel1");
Check that you have "Panel1" named Panel with you.
===========
I don't think you must be getting error at the location specified by you.
string boxName = "TextBoxID" + (i + 1).ToString();
There is nothing wrong with this statement.