title: Access text box value created dynamically when check box is checked
body: <p>I am a litle confused with ASP.NET lifecycle event. I have a checkbox when it is checked, it will dynamically create labels and text boxes. This is done in checkbox oncheckchanged event.I have Ajax enabled on the checkbox without full postback.</p>
  
  <p>Now in the newly created text boxes I am entering the values and when I click on the save button, in the button click event it would not even find the controls created. So how does the page viewstate remember the dynamic controls created in the checkbox events and then access it's values in the button save event?
  Mark up:</p>
  
  <pre><code>                  &lt;tr&gt; &lt;td&gt; &lt;asp:CheckBox ID="chkType" runat="server" Text="Medical Procedure" OnCheckedChanged="ChkMedicalProc_Clicked"&gt;&lt;/td&gt;&lt;/tr&gt;
  
                  &lt;tr&gt;&lt;td colspan="2"&gt;
                      &lt;asp:PlaceHolder ID="dyna" EnableViewState="true" runat="server"&gt;&lt;/asp:PlaceHolder&gt;
                  &lt;/td&gt;&lt;/tr&gt;
  </code></pre>
  
  <p>Code behind in the checkedchanged event:</p>
  
  <pre><code>TableRow tr = new TableRow();
              TableCell tc1 = new TableCell();
              TableCell tc2 = new TableCell();
              Label lbl = new Label();
              lbl.Text = string.Empty;
              lbl.Text = (_queryParam[i].Param_Name + " (" + _queryParam[i].Param_Type + ") (" + _queryParam[i].Param_Length + ")").ToString();
              lbl.Style.Add("font-size", "11px");
              lbl.Style.Add("font-family", "Arial");
              _txtBox = new TextBox();
              _txtBox.ID = ctrlId;
              _txtBox.CssClass = "textEntry";
              _txtBox.Text = string.Empty;
              _txtBox.Text = _queryParam[i].Param_Value;
              tc1.Style.Add("width", "21.8%");
              tc1.Controls.Add(lbl);
              tc2.Controls.Add(_txtBox);
              tr.Cells.Add(tc1);
              tr.Cells.Add(tc2);
  
              _tbl.Rows.Add(tr);
  
              this.Master.FindControl("pagecontent1").FindControl("dyna").Controls.Add(_tbl);
  </code></pre>
  
  <p>Save button click event:</p>
  
  <pre><code>  for (int i = 0; i &lt; box.Count; i++)
                                  {
                                      TextBox boxValue= this.Page.Master.FindControl("pagecontent1").FindControl("dyna").FindControl("txtBoxParams-" + i) as TextBox;
                                     //I get object reference error on boxValue
  }
  </code></pre>