protected override void Render(HtmlTextWriter output)
{
this.Controls.Clear();
Button Button1 = new Button();
Button1.Width = 88;
Button1.Text = "建立文档";

DropDownList DropDownList1 = new DropDownList();
DropDownList1.Width = 100;

this.Controls.Add(Button1);
this.Controls.Add(DropDownList1);
this.RenderChildren(output);

}

解决方案 »

  1.   

    在CreateChildControls里加入子控件
      

  2.   

    //这是VB的自定义控件的例子
    Imports System.ComponentModel
    Imports System.Web.UI
    Imports System.Web.UI.Page
    Imports System.Web.UI.WebControls
    Imports System.Data
    Imports System.Data.SqlClient<DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")> Public Class WebCustomControl1
        Inherits System.Web.UI.WebControls.WebControl    Dim _text As String
          <Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
            Get
                Return _text
            End Get        Set(ByVal Value As String)
                _text = Value
            End Set
        End Property
        Public Label1 As Label
        Dim add As New Button
        Dim del As New Button
        Dim value1 As New TextBox
        Dim search As New Button
        Dim DropDownList1 As New DropDownList
        Dim compare1 As New DropDownList    
        Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
            Controls.Clear()
            add.Text = "加"
            del.Text = "减"
            compare1.Items.Add(New ListItem("<", "<"))
            compare1.Items.Add(New ListItem("<=", "<="))
            compare1.Items.Add(New ListItem("=", "="))
            compare1.Items.Add(New ListItem(">", ">"))
            compare1.Items.Add(New ListItem(">=", ">="))        search.Text = "查询"
            AddHandler add.Click, AddressOf Me.add_Click        Controls.Add(add)
            Controls.Add(del)
            Controls.Add(DropDownList1)
            Controls.Add(compare1)
            Controls.Add(value1)
            Controls.Add(search)
            Controls.Add(New LiteralControl("<br>"))
            Label1 = New Label
            Controls.Add(Label1)
            RenderChildren(output)
        End SubEnd Class
    你试试看吧