I am looking to create a user/server control that will be created with something like the following:
<my:MyListControl runat="server">
<asp:ListItem Text="Test1" Value="Test1" />
<asp:ListItem Text="Test2" Value="Test2" />
</my:MyListControl>
I am just looking for a start here: Articles or code samples.
What base class should I inherit from? What to override?
Possibly how to customize what sub items my control accepts (my:ListItem instead of asp:ListItem).
What I am looking to do is create a very simple bread crumb control for a small section of my site. I have it all working with stock ASP.NET controls, but the items are added in code, which means fixing a spelling mistake or formatting bug involves a recompile, which is not ideal.
EDIT:
Here's my code with the addition of Josh's suggestion below:
Namespace MySite.Controls Partial Class BreadCrumbs Inherits UserControl
Private m_BreadCrumbs As New List(Of BreadCrumbItem)
<PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property Items() As List(Of BreadCrumbItem)
Get
Return m_BreadCrumbs
End Get
Set(ByVal value As List(Of BreadCrumbItem))
m_BreadCrumbs = value
End Set
End Property
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Bind()
End Sub
Private Sub Bind()
lvCrumbs.DataSource = Items
Me.DataBind()
End Sub
End Class
Public Class BreadCrumbItem
Private m_Text As String
Public Property Text() As String
Get
Return m_Text
End Get
Set(ByVal value As String)
m_Text = value
End Set
End Property
Private m_Url As String
Public Property Url() As String
Get
Return m_Url
End Get
Set(ByVal value As String)
m_Url = value
End Set
End Property
End Class
End Namespace
Then my page code looks like this:
<%@ Page Language="VB" AutoEventWireup="false" Inherits="MySite.MyPage" Title="My Page" Codebehind="MyPage.aspx.vb" %>
<%@ Register TagPrefix="my" TagName="BreadCrumbs" Src="~/BreadCrumbs.ascx" %>
<%@ Register TagPrefix="my" Namespace="MySite.Controls" Assembly="MySite" %>
<rc:BreadCrumbs ID="breadcrumbs" runat="server">
<Items>
<my:BreadCrumbItem Text="Another page" Url="AnotherPage.aspx" />
</Items>
</rc:BreadCrumbs>