質問

「N00B」私を呼び出して、私は、スクリプトコントロールを作成するには新しいです。私は3つのテキストボックスと簡単なコントロールを作成します。私はこのようになりますする.csファイルを持っています:

    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;
    }
}
テキストボックスには文句を言わないレンダリングなぜ

と私は絶対にないアイデアを持っていませんか?私は何かが足りないと思う...

[EDIT]私は取得していますエラーは、「オブジェクト参照がオブジェクトにインスタンスに設定されていません」です。

[ANSWERED]これまでのところ、少なくとも、次のように私は、ファイルを変更し、それが動作します。

   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();
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top