show your Render code, either you need to add Button to your Controls before you call base.Render or render it specifically with Button.RenderControl(writer), show your codeby the way, it is a bad idea to add controls in Render

解决方案 »

  1.   

    public class TestComponent: System.Web.UI.WebControls.Panel, INamingContainer
    {
    private Label label1 = new Label();
    private Label label2 = new Label();
    private Button button1 = new Button(); public TestComponent()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    button1.Text = "demo";
    label1.Text = "Hello!";
    label2.Text = "Goodbye!";
    } protected override void CreateChildControls()
    {

    Controls.Add (label1);
    Controls.Add (label2);
    Controls.Add(button1); base.CreateChildControls();
    }
    protected override void Render(HtmlTextWriter output)
    { this.label1.RenderControl(output);
    this.label2.RenderControl(output); this.button1.RenderControl(output);
    }
    }
      

  2.   

    it works fine on my machine in a browser, do you mean design-time support? it is a container, you shouldn't add controls in the code, you should add them in html
      

  3.   

    it works fine on my machine in a browser, do you mean design-time support? it is a container, you shouldn't add controls in the code, you should add them in html
      

  4.   

    saucer(思归):
      我确实是想在设计期间看见用代码添加的组件.因为我想做一个GroupBox.
      请问就没有解决办法吗?
      

  5.   

    according to Microsoft, it is not possible to have ReadWriteControlDesigner and GetDesignTimeHtml work at the same time, but you might want to look into this post:http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=94dd4aac.0302240954.62a3b347%40posting.google.com
      

  6.   

    according to Microsoft, it is not possible to have ReadWriteControlDesigner and GetDesignTimeHtml work at the same time, but you might want to look into this post:http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=94dd4aac.0302240954.62a3b347%40posting.google.com
      

  7.   

    在页面创建一个panel控件
    Button bt=new Button();
    this.panel.Control.Add(bt);需要一个容器承载这个控件
      

  8.   

    继承RenderChildren()方法:
    protected override void RenderChildren(HtmlTextWriter writer) 
    {
         button.RenderControl(writer);
    }
      

  9.   

    xiandaliu(仙达流):
    你好,其实如果从Panel继承,用override RenderChildren的方法也是没办法解决的
      

  10.   

    试试style="Z-INDEX: 99999;"行不行。
      

  11.   

    saucer(思归):
    你好, 
    我根据你指的url(http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=94dd4aac.0302240954.62a3b347%40posting.google.com),把那个例子搬了下来,但是一直出错,我又照着做了一个,还是有问题:我设计了一个设计器,从ReadWriteControlDesigner继承
    请问为什么我在获取这个设计器的DesignTimeElement属性时,一直为空呢?
    而且为什么线程也没有执行?
    class MyDesignerClass : ReadWriteControlDesigner, IDisposable
    { System.Web.UI.Design.ReadWriteControlDesigner c;
    string ret;
    private string _html;
            private Thread _th;
    mshtml.IHTMLElement element; private void parsecrtls()
    {
    mshtml.IHTMLElement e; while(true)
    {
    try
    {
    e = (mshtml.IHTMLElement)this.DesignTimeElement;

    System.Diagnostics.Debug.WriteLine(a);
    if(e.innerHTML != this._html)
    {
    OninnerContentChange(e.innerHTML);
    this._html = e.innerHTML;
    }
    }
    catch(Exception ex)
    {
    throw ex;
    }
    Thread.Sleep(50);
    }
    }

    public MyDesignerClass()
    :base()
    {
                               //问题一:线程不执行,因为在这里不出错
               this._html = "";
    _th = new Thread(new ThreadStart(parsecrtls));
    _th.Priority = ThreadPriority.Highest;
    _th.Start();
                               //-----------------------------                            //问题二:DesignTimeElement为null,因为它出错
    if(this.DesignTimeElement == null)
    {
    element = (mshtml.IHTMLElement)this.DesignTimeElement;
    element.innerText = "<table><tr><td>abcdefg</td></tr><table>"; //这里出错
    }
                                //--------------------------------------------
    }
    protected void Displose()
    {
    base.Dispose();
    this._th.Abort();
    } protected void OninnerContentChange(System.String innerContent)
    {
    innerContent = innerContent + "*";
    } public override bool AllowResize
    {
    get
    {
    return true;
    }
    }

    }
      

  12.   

    sorry, the code in that post seems like a hack to me, I tried once and didn't make it work, so I gave up