I am trying to develop a control that'll allow the developer to populate a collection through markup (e.g. Properties decorated with the attribute PersistenceMode(PersistenceMode.InnerProperty). I have an example from Brian Chavez that more or less does what I want but I want to have the control inherit from UserControl and not Control.
Here is the code I have in vb.net:
AggregateFeeds.ascx.vb
Imports Microsoft.VisualBasic
<ParseChildren(True)>
<PersistChildren(False)>
Public Class AggregateFeeds
Inherits UserControl
Public Sub New()
MyBase.New()
Me.Feeds = New RssFeedCollection()
Me.Settings = New AggregateSettings()
End Sub
Private _Feeds As RssFeedCollection
Private _Settings As AggregateSettings
<PersistenceMode(PersistenceMode.InnerProperty)>
Public Property Feeds As RssFeedCollection
Get
Return _Feeds
End Get
Private Set(ByVal value As RssFeedCollection)
_Feeds = value
End Set
End Property
<PersistenceMode(PersistenceMode.InnerProperty)>
Public Property Settings As AggregateSettings
Get
Return _Settings
End Get
Private Set(ByVal value As AggregateSettings)
_Settings = value
End Set
End Property
End Class
Public Class AggregateSettings
Public Property TimeOut As Integer
Public Property CacheResults As Boolean
Public Sub New()
TimeOut = 100
CacheResults = True
End Sub
End Class
Public Class RssFeedCollection
Inherits List(Of RssResource)
End Class
Public Class RssResource
Public Property Url As String = String.Empty
End Class
The ascx file just looks like:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ucAdminTabControl.ascx.vb" Inherits="AggregateFeeds" %>
My test page is real simple and looks like:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %>
<%@ Register Src="~/Survey/Controls/ucAdminTabControl.ascx" TagName="AggregateFeeds" TagPrefix="uc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:AggregateFeeds runat="server" ID="af">
<Settings CacheResults="False" TimeOut="250" />
<Feeds>
<uc:RssResource Url="http://test.com" />
</Feeds>
</uc:AggregateFeeds>
</div>
</form>
</body>
</html>
As it is now when I try to compile I get a compiler error that simply says object instance not set to an instance of an object on the line above. If I take it out, the page loads just fine and the Settings object reflects the values in the markup. Why am I having trouble getting the collection to populate correctly?