title: How to dynamically create and add textbox to a placeholder using AJAX?
body: <p>I'm trying to create text box dynamically. so I cal  it through the AJAX function. </p>
  
  <p>This is my code:</p>
  
  <p><strong>Ajax function</strong></p>
  
  <pre><code>function ChangedAdults(noofAdults) {
      alert(noofAdults.value);
      $.ajax({
  
          type: 'POST',
          dataType: 'json',
          url: "/FlightBooking.aspx/Adults",
  
          data: "{noOfAdults:'" + noofAdults.value +  "'}",
          contentType: "application/json; charset=utf-8",
          success: function (result) {
                       $("#AdultsList").html(result.d);
                   },
          error: function (xhr, ajaxOptions, thrownError) {
                     alert(xhr.status);
                     alert(thrownError);
                 }
      });
  }
  </code></pre>
  
  <p><strong>code behind</strong></p>
  
  <pre><code>[WebMethod]
  public static string Adults(int noOfAdults)
  {
      FlightBooking obj = new FlightBooking();
      obj.CreateAdultsList(noOfAdults);          
  
      string test= "";
      return test.ToString();
  }
  private void CreateAdultsList(int noOfAdults)
  {
      int n = noOfAdults;
      for (int i = 0; i &lt; n; i++)
      {
          TextBox MyTextBox = new TextBox();                      
          MyTextBox.ID = "tb" + "" + i;    
          AdultsListPlaceholder.Controls.Add(MyTextBox); //error coming here
          AdultsListPlaceholder.Controls.Add(new LiteralControl("&lt;br /&gt;"));
      }
  }
  </code></pre>
  
  <p>But I receive an error:</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object </p>
  </blockquote>
  
  <p>What could cause this problem?</p>