这个很简单呀、
比如
Public MustInherit Class DdlList
    Inherits System.Web.UI.UserControl
    Protected WithEvents lsbMessage As System.Web.UI.WebControls.ListBox
    Protected WithEvents btnGo As System.Web.UI.WebControls.Button
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
    Protected WithEvents ddlMessage As System.Web.UI.WebControls.DropDownList
--------------
--------------它的属性:
 '获取ListBox.SelectedItem.Text
    Public ReadOnly Property lsbSelectText() As String
        Get
            If lsbMessage.SelectedIndex > -1 Then
                Return lsbMessage.SelectedItem.Text
            Else
                Return ""
            End If
        End Get
    End Property它的属性:    
    
    '获取或设置视图名
    Public ReadOnly Property getListBox() As Control
        Get
            Return lsbMessage
        End Get    End PropertyEnd Class

解决方案 »

  1.   

    你写的属性怎么只有Get,没有Set ?
      

  2.   

    在你自定义的webcontrol中定义属性:
    private int m_intTypeID;
    public int TypeID
    {
         get
         {
            return this.m_intTypeID;
         }
         set
         {
            this.m_intTypeID=value
         }
    }
    在aspx页面中添加该控件后,进行对属性的设置(两种方法)
    1.在page_load(或其它位置)方法中:该控件的实例名.TypeID=yourValue;
    2.在html文件中:<uc:该控件的实例名 TypeID=yourValue/>
      

  3.   

    谢谢大家的回答
    其实我也写过几个web自定义控件,我现在正写一个继承WebControl的控件
    “如何写一属性,就象DropDownList的Items一样?”呢?。
    就象DropDownList的Items 的意思是说:
    1、能在aspx里设计时在属性栏里点Items 能出现和DropDownList的Items一样的对话框;
    2、对话框里添加了项目后,aspx文件里能出现类似 <asp:DropDownList id="DropDownList1" runat="server">
    <asp:ListItem Value="item1">item1</asp:ListItem> <asp:ListItem Value="item2">item2</asp:ListItem> </asp:DropDownList>;
    3、能有DropDownList1.Items.Add(...)类似的add方法;
    拜托各位了,小弟先给大家鞠躬!
      

  4.   

    我的代码是这样的
    public ListItem[] Items
    {
    get
    {
    return items;
    }
    set
    {
    items = value;
    }
    }
    能实现我描述的第一项功能:能在aspx里设计时在属性栏里点Items 能出现和DropDownList的Items一样的对话框;
      

  5.   

    首先要实现你自己的ItemCollection,要实现IList然后属性定义是:ItemCollection _items=new ItemCollection();
    [
    DefaultValue(null),
    PersistenceMode(PersistenceMode.InnerProperty),
    NotifyParentProperty(true),
    ]
    public ItemCollection Items
    {
    get{return _items;}
    }
      

  6.   

    ItemCollection _items=new ItemCollection();
    this
    [
    DefaultValue(null),
    PersistenceMode(PersistenceMode.InnerProperty),
    NotifyParentProperty(true),
    ]
    public ItemCollection Items
    {
    get{return _items;}
    }
      

  7.   

    msdn上有介绍。去哪里搜索一下吧