Exposing ListItems in Composite Control

Discussion in 'ASP .Net Building Controls' started by Lisa, Sep 8, 2004.

  1. Lisa

    Lisa Guest

    I'm trying to build a composite control that consists of a select
    inside a div (a listbox inside a panel). My problem is that when I
    compile the control and drag it onto a webform, the Items collection
    property that shows up in the Properties window of VS.net doesn't give
    me Items for my control. What I wind up with when I put items in is
    this:

    <cc1:LLList id="LLList2" runat="server">
    <asp:ListItem Value="test">test</asp:ListItem>
    </cc1:LLList>

    What I want to see is this:

    <cc1:LLList id="LLList2" runat="server">
    <cc1:Item Value="test">test</cc1:ListItem>
    </cc1:LLList>

    Here is the code for the control. I'm using PersistenceMode and such,
    but it doesn't seem to be having any affect.

    Imports System
    Imports System.IO
    Imports System.ComponentModel
    Imports System.Web
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.HtmlControls

    <ToolboxData("<{0}:LLList runat=server></{0}:LLList>")> _
    Public Class LLList
    Inherits System.Web.UI.WebControls.WebControl
    Implements INamingContainer

    Private _listbox As ListBox
    Private _panel As Panel

    Protected Overridable Sub Initialize()
    Me.Width = WebControls.Unit.Pixel(100)
    Me.Height = WebControls.Unit.Pixel(100)
    End Sub

    Public Overrides ReadOnly Property Controls() As ControlCollection
    Get
    EnsureChildControls()
    Return MyBase.Controls
    End Get
    End Property

    Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
    MyBase.OnPreRender(e)
    RegisterScript()
    End Sub

    Protected Overridable Sub RegisterScript()
    If Not Page.IsClientScriptBlockRegistered("LLList_js") Then
    Dim reader As New
    System.IO.StreamReader(Me.GetType().Assembly.GetManifestResourceStream(Me.GetType(),
    "LLList.js"))
    Dim script As String = "<script language='javascript'
    type='text/javascript' >" + ControlChars.Cr + ControlChars.Lf + "<!--"
    + ControlChars.Cr + ControlChars.Lf + reader.ReadToEnd() +
    ControlChars.Cr + ControlChars.Lf + "//-->" + ControlChars.Cr +
    ControlChars.Lf + "</script>"
    Page.RegisterClientScriptBlock("LLList_js", script)
    End If
    End Sub

    #Region "Properties delegated to child controls"

    <Bindable(True), Browsable(True), Category("Misc"),
    PersistenceMode(PersistenceMode.InnerProperty),
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
    NotifyParentProperty(True)> _
    Public ReadOnly Property Items() As ListItemCollection
    Get
    Me.EnsureChildControls()
    Return _listbox.Items
    End Get
    End Property

    #End Region

    Protected Overrides Sub CreateChildControls()

    Controls.Clear()

    _listbox = New ListBox
    _panel = New Panel

    _listbox.ID = "ListBox"
    _listbox.Attributes("onchange") = "LLShowOption(this,
    this.selectedIndex)"
    _listbox.Attributes("onkeypress") = "LLAlphaSearch(this)"

    _panel.ID = "ParentDiv"
    _panel.Controls.Add(_listbox)

    _panel.Attributes("style") = "overflow:scroll;
    border-width:thin; border-style:inset"
    ' _panel.Attributes("style") = "overflow:scroll;
    width:" & Me.Width.ToString & "; height:" & Me.Height.ToString & ";
    border-width:thin; border-style:inset"

    Controls.Add(_panel)

    End Sub

    Protected Overrides Sub Render(ByVal output As
    System.Web.UI.HtmlTextWriter)
    Me.EnsureChildControls()
    RenderContents(output)
    End Sub

    End Class

    Am I doing something obviously wrong? And... if I want to expose
    every property from the Listbox, do I have to expose them each
    individually, or is there a way I can do them all globally? I would
    have been happy to just inherit the Listbox and put the Panel/Div
    around it, but apparently you can't do that.

    Thanks,
    Lisa
     
    Lisa, Sep 8, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sleigh
    Replies:
    1
    Views:
    2,707
    sleigh
    Feb 12, 2004
  2. Jeff
    Replies:
    1
    Views:
    6,534
    Bruce Barker
    Mar 18, 2005
  3. Chad
    Replies:
    0
    Views:
    237
  4. Lisa

    Exposing ListItems in Composite Control

    Lisa, Sep 9, 2004, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    234
    Alessandro Zifiglio
    Sep 23, 2004
  5. Steve Trandahl

    DropDownList in composite control not saving ListItems

    Steve Trandahl, May 26, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    292
    Steve Trandahl
    May 27, 2005
Loading...

Share This Page