make sure the ascx's parent page has 
<form enctype="multipart/form-data" runat="server">

解决方案 »

  1.   

    public string Text
                {
                      get
                      {
                        EnsureChildControls();
                            return label.Text;
                      }
                      set
                      {
                        EnsureChildControls();
                            label.Text = value;
                      }
                }protected override void CreateChildControls() 
                {
                      
                      Controls.Add(new LiteralControl("<h3>Enter a number : "));
                      
                      TextBox box1 = new TextBox();
                      box1.Text = "0";
                      Controls.Add(box1);
                      
                      Controls.Add(new LiteralControl("</h3>"));
                      
                      Controls.Add(new LiteralControl("<h3>Enter another number : "));
                      
                      TextBox box2 = new TextBox();
                      box2.Text = "0";
                      Controls.Add(box2);
                      
                      Controls.Add(new LiteralControl("</h3>"));
                      
                      Button button1 = new Button();
    }在引用之前调用EnsureChildControls();在CreateChildControls() 初始化子控件,这样,如果调用EnsureChildControls()时没有子控件,则系统调用CreateChildControls() 来创建子控件
      

  2.   

    <form enctype="multipart/form-data" runat="server">