title: can not read value from dynamically create control
body: <p>I am stuck with following issue.I've google a lot and try every method but could not solve issue</p>
  
  <p>I am creating control dynamically and after that reading value from dynamically created control</p>
  
  <p>but every time I get error "Object reference is not set to an instance of an object" means I am not able to locate the control even if it available on page.</p>
  
  <p>here is my code</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
   {
  
  
  
  TextBox txt = new TextBox();
     txt.ID = "myText";
     txt.ViewStateMode = System.Web.UI.ViewStateMode.Enabled;
     Panel1.Controls.Add(txt);
  
   }
  
   protected void Button2_Click(object sender, EventArgs e)
   {
  
         TextBox txt = Panel1.FindControl("myText") as TextBox;
  
         Response.Write(txt.Text);
  
   }
  </code></pre>
  
  <p>Here is aspx page code :</p>
  
  <pre><code>&lt;div&gt;
     &lt;asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /&gt;
  
     &lt;asp:Panel ID="Panel1" runat="server"&gt;&lt;/asp:Panel&gt;
  
     &lt;asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click"/&gt;
  &lt;/div&gt;
  </code></pre>