Allowing a Server Control to Contain Custom Child Collection

I’ve probably done this at least a dozen times, but when you don’t do something everyday, you tend to forget. I created a custom control that I wanted to place into a control collection. So, I created the child control as a custom server control. Then I created another server control that contained a property called Items as a Generic.List(Of T) where T was my custom child control. I kept running my app and couldn’t figure out why I couldn’t create my child controls in the Parent. I forgot that I had to import the namespace System.ComponentModel and add the PersistenceMode property to the property. So, my code looked like this:


Visual Basic



Public Class MyServerControlCollection
    
Inherits WebControl

    
Private _Items As Generic.List(Of MyChildControl)

    <PersistenceMode(PersistenceMode.InnerProperty)> _
    Public Property Items() As Generic.List(Of MyChildControl)
        
Get
            Return 
_Items
        
End Get
        Set
(ByVal value As Generic.List(Of MyChildControl))
            _Items 
value
        
End Set
    End Property

    Protected Overrides Sub 
CreateChildControls()
        
For Each obj As MyChildControl In Items
            
Me.Controls.Add(obj)
        
Next

        MyBase
.CreateChildControls()
    
End Sub

End Class

C#



public class MyServerControlCollection : WebControl
{

    
private Generic.List<MyChildControl> _Items;

    [PersistenceMode(PersistenceMode.InnerProperty)]
    public 
Generic.List<MyChildControl> Items {
        
get return _Items}
        
set { _Items = value; }
    }

    
protected override void CreateChildControls()
    {
        
foreach (MyChildControl obj in Items) {
            
this.Controls.Add(obj);
        
}

        
base.CreateChildControls();
    
}

}

Hope that helps!

Internet Explorer 8 Beta 1 – Websites that are Broken

IE8 Beta 1 now forces CSS 2.1 along with other web standards (includes some early HTML 5 stuff too!). I’m creating a list of websites that seem to be broken by the browser. Feel free to leave a comment if you come across other sites. Here’s what I found so far (notice that only part of the site may be broken and not necessarily all of the site):

  • http://dell.com (missing menu bar at the top and bottom)
  • http://cnn.com (textbox at the bottom on the page)
  • http://nbc.com (content layout)
  • http://yahoo.com (search bar)
  • http://asp.net (content layout)
  • http://gm.com (where’s the content?)
  • http://officemax.com (missing some menu in the left column)
  • http://homedepot.com (some elements are not aligned properly)
  • http://news.com (items not aligned properly)
  • http://facebook.com (main page)