Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 190881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:17:38+00:00 2026-05-11T16:17:38+00:00

I am looking to create a user/server control that will be created with something

  • 0

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" Namespace="MySite.Controls" Assembly="MySite" %>
<my:BreadCrumbs ID="breadcrumbs" runat="server">
    <Items>
        <my:BreadCrumbItem Text="Another page" Url="AnotherPage.aspx" />
    </Items>
</my:BreadCrumbs>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:17:38+00:00Added an answer on May 11, 2026 at 4:17 pm

    You can add a property on a user control’s code behind like:

    [PersistenceMode(PersistenceMode.InnerProperty)]
    public List<ListItem> Items
    {
        get;
        set;
    }
    

    Your markup would then be:

    <my:MyListControl runat="server">
      <Items>
        <asp:ListItem/>
      </Items>
    </my:myListControl>
    

    To make it so ListItem can be your own list item (Which I recommend doing as opposed to using asp.net.) You’ll want to create your own class.

    Here’s an example of a Server Control I use (I removed a lot of the noise as such this is just a skeleton):

       [ToolboxData("<{0}:Menubar runat=server></{0}:Menubar>")]
        [System.ComponentModel.DesignTimeVisible(false)]
        public class Menubar : WebControl, IPostBackEventHandler
        {
    
            private List<MenuItem> _menuItems = new List<MenuItem>();
            [PersistenceMode(PersistenceMode.InnerProperty)]
            public List<MenuItem> MenuItems
            {
                get
                {
                    return _menuItems;
                }
            }
    
        }
        [ToolboxItem(false)]
        [ParseChildren(true, "MenuItems")]
        public class MenuItem
        {
            private string _clientClick;
            private List<MenuItem> _menuItems = new List<MenuItem>();
    
            [Localizable(true)]
            public string Title { get; set; }
            public string Href { get; set; }
            public string Id { get; set; }
            [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
            public List<MenuItem> MenuItems
            {
                get { return _menuItems; }
                set { _menuItems = value; }
            }
        }
    

    Now I can use this like:

    <my:Menubar runat="server" ID="menuBar">
        <MenuItems>
            <my:MenuItem Title="Save" Href="javascript:saveItem(this);"  />
            <my:MenuItem Title="Print" Href="javascript:void(0);">
                <MenuItems>
                    <my:MenuItem Title="Preview" Href=""/>
                    <my:MenuItem Title="To Pdf" Href="javascript:"/>
                </MenuItems>
            </my:MenuItem>
        </MenuItems>
    </my:Menubar>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 93k
  • Answers 93k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer struct Cmp { explicit Cmp(int mode) : mode_(mode) {} bool… May 11, 2026 at 6:38 pm
  • Editorial Team
    Editorial Team added an answer perl -MLWP::Simple -e 'getprint "http://ru.wikipedia.org/wiki/Perl"' 403 Forbidden <URL:http://ru.wikipedia.org/wiki/Perl> Well, that… May 11, 2026 at 6:38 pm
  • Editorial Team
    Editorial Team added an answer Yup, via the onorientationchange event and the window.orientation property. Documented… May 11, 2026 at 6:38 pm

Related Questions

I am looking for libraries that would help in programatically manipulating EPS (Encapsulated PostScript)
I have a web-app-database 3 tier server setup. Web requests data from app, and
i am looking for svn admin a desktop application like VisualSVN Server only for
We are designing a survey application with the following features The users will be
I'm looking for a good article or two, or just an explanation, on how

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.