Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 122919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:12:17+00:00 2026-05-11T04:12:17+00:00

Call me a ‘n00b’, but I am new to creating Script Controls. I want

  • 0

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:

    public class SmokingCalc : ScriptControl     {         public SmokingCalc()         {             Render(htmlWriter);         }         protected override void Render(HtmlTextWriter writer)         {             costTextbox.RenderControl(writer);             base.Render(writer);         }         protected override IEnumerable<ScriptDescriptor>                 GetScriptDescriptors()         {             ScriptControlDescriptor descriptor = new ScriptControlDescriptor('SmokingCalc.SmokingCalc', this.ClientID);             yield return descriptor;         }          // Generate the script reference         protected override IEnumerable<ScriptReference>                 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;     } } 

and I have absolutely no idea why the textbox wont render? I think I am missing something…

[EDIT] The error I’m getting is the ‘Object reference is not set to an instance to an object’.

[ANSWERED] I changed the file as follows, and it works, so far at least.

   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<ScriptDescriptor>                 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<ScriptReference>                 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();     } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T04:12:17+00:00Added an answer on May 11, 2026 at 4:12 am

    Did you try CreateChildControls?:

    public class SmokingCalc : ScriptControl {     protected override void CreateChildControls()     {         this.Controls.Add(costTextbox);     }      protected override IEnumerable<ScriptDescriptor>             GetScriptDescriptors()     {         ScriptControlDescriptor descriptor = new ScriptControlDescriptor('SmokingCalc.SmokingCalc', this.ClientID);         yield return descriptor;     }      // Generate the script reference     protected override IEnumerable<ScriptReference>             GetScriptReferences()     {         yield return new ScriptReference('SmokingCalc.SmokingCalc.js', this.GetType().Assembly.FullName);     }      protected HtmlTextWriter htmlWriter;     protected TextBox costTextbox = new TextBox();     protected TextBox amountTextbox = new TextBox();     protected TextBox yearsTextbox = new TextBox();     protected Button submitButton = new Button(); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We call a .live() method like this: $('.link').live('click', loadContent); But what about if I'm
The call Character.isLetter(c) returns true if the character is a letter. But is there
If you want to call a C/C++ function from inline assembly, you can do
I call a template like this: <xsl:call-template name=trip_form> <xsl:with-param name=header select='Spara din resa' />
This call // this._cfg is an NHibernate Configuration instance this._sessionFactory = this._cfg.BuildSessionFactory(); Gives me
I call a webservice via HttpWebRequest. Now the owner of the service send a
i call the url of googlemaps to show a position to a given lat
I call a piece of an unmanaged C++ code from my C# application to
How do I call a class from a string containing that class name inside
How do I call Zedgraph's function masterPane.SetLayout() from Web C# Application? Basically i'm stuck

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.