title: Creating an AJAX Script Control
body: <p>Call me a 'n00b', but I am new to creating Script Controls. I want to create a simple control with 3 text boxes. I have a .cs file that looks like this:</p>
  
  <pre><code>    public class SmokingCalc : ScriptControl
      {
          public SmokingCalc()
          {
              Render(htmlWriter);
          }
          protected override void Render(HtmlTextWriter writer)
          {
              costTextbox.RenderControl(writer);
              base.Render(writer);
          }
          protected override IEnumerable&lt;ScriptDescriptor&gt;
                  GetScriptDescriptors()
          {
              ScriptControlDescriptor descriptor = new ScriptControlDescriptor("SmokingCalc.SmokingCalc", this.ClientID);
              yield return descriptor;
          }
  
          // Generate the script reference
          protected override IEnumerable&lt;ScriptReference&gt;
                  GetScriptReferences()
          {
              yield return new ScriptReference("SmokingCalc.SmokingCalc.js", this.GetType().Assembly.FullName);
          }
  
          protected HtmlTextWriter htmlWriter;
          protected TextBox costTextbox;
          protected TextBox amountTextbox;
          protected TextBox yearsTextbox;
          protected Button submitButton;
      }
  }
  </code></pre>
  
  <p>and I have absolutely no idea why the textbox wont render? I think I am missing something...</p>
  
  <p>[EDIT] The error I'm getting is the "Object reference is not set to an instance to an object".</p>
  
  <p>[ANSWERED] I changed the file as follows, and it works, so far at least.</p>
  
  <pre><code>   public class SmokingCalc : ScriptControl
      {
          public SmokingCalc()
          {
          }
          protected override void CreateChildControls()
          {
              base.CreateChildControls();
              costTextbox.ID = "costTextbox";
              amountTextbox.ID = "amountTextbox";
              yearsTextbox.ID = "yearsTextbox";
              submitButton.ID = "submitButton";
              submitButton.Text = "Submit";
              Controls.Add(costTextbox);
              Controls.Add(amountTextbox);
              Controls.Add(yearsTextbox);
              Controls.Add(submitButton);
          }
          protected override IEnumerable&lt;ScriptDescriptor&gt;
                  GetScriptDescriptors()
          {
              ScriptControlDescriptor descriptor = new ScriptControlDescriptor("SmokingCalc.SmokingCalc", this.ClientID);
              descriptor.AddProperty("costTextboxID", costTextbox.ClientID);
              descriptor.AddProperty("amountTextboxID", amountTextbox.ClientID);
              descriptor.AddProperty("yearsTextboxID", amountTextbox.ClientID);
              descriptor.AddProperty("submitButtonID", submitButton.ClientID);
              yield return descriptor;
          }
  
          // Generate the script reference
          protected override IEnumerable&lt;ScriptReference&gt;
                  GetScriptReferences()
          {
              yield return new ScriptReference("SmokingCalc.SmokingCalc.js", this.GetType().Assembly.FullName);
          }
  
          protected TextBox costTextbox = new TextBox();
          protected TextBox amountTextbox = new TextBox();
          protected TextBox yearsTextbox = new TextBox();
          protected Button submitButton = new Button();
      }
  </code></pre>