asp.net findcontrol method return null
<p>I am creating some dyanamic textbox on a button click event and on another button click i want to fetch data of that textbox using findcontrol method </p>

<pre><code> public void addDepartmentBtn_Click(object sender, EventArgs e)
    {

        int count = Convert.ToInt32(countTxtBx.Text);
        lblErrorMsg.Text = "";
        if (Convert.ToInt32(countTxtBx.Text) &lt;= 5)
        {

            for (int i = 0; i &lt; count; i++)
            {
                Label lb = new Label();
                TextBox tb = new TextBox();

                tb.ID = "Textbox_" + i;
                lb.ID = "Label_" + i;
                lb.Text = "Enter Departnment Name: " + Convert.ToInt32(i + 1);
                pnlMain.Controls.Add(new LiteralControl("&lt;br&gt;"));
                pnlMain.Controls.Add(lb);
                pnlMain.Controls.Add(new LiteralControl("&amp;nbsp&amp;nbsp"));
                pnlMain.Controls.Add(tb);
                pnlMain.Controls.Add(new LiteralControl("&lt;br&gt;&lt;br&gt;"));
                lblErrorMsg.Text = Convert.ToInt32(i + 1) + "  Departments Created Successfully";
                //string str = string.Empty;
                //TextBox myTB = (TextBox)pnlMain.FindControl("Textbox_" + i);
                //str = myTB.Text;
                //Response.Write(str);

            }

        }
        else
        {
            lblErrorMsg.Text = "You cannot create more than 5 Departments at once:";
        }
    }
</code></pre>

<p>On button2 click:</p>

<pre><code>   protected void Button2_Click(object sender, EventArgs e)
        {
            string alltextdata = null;
            for (int i = 0; i &lt; 5; i++)
            {
                Control controltxt = FindControl("Textbox_"+i);
                if (controltxt != null)
                {
                    TextBox txttemp = (TextBox)controltxt;
                    alltextdata = txttemp.Text;

                }
            }

        }
</code></pre>

<p>but my find control method alway show me null i check my html page view source which show me every thing correct my textbox name and id is "Textbox_0",Textbox_1 etc </p>

<p>am i doing some mistake ? please help</p>
