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 6187007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:59:17+00:00 2026-05-24T01:59:17+00:00

I am trying to write a template custom control in C#, ASP.NET that will

  • 0

I am trying to write a template custom control in C#, ASP.NET that will have a collection of items. I’d like to use it similarly to the built-in DropDownList control in ASP.NET, but my items will have different properties.

I noticed that the ListItem class that is used to represent the items in a DropDownList control (or any list control) implements the IParserAccessor interface. When should I implement this interface and what should I do in its AddParsedSubObject(object obj). I’ve searched the internet but I could not find an example or a good explanation for it.

I assume that my custom control’s items will make it without implementing that interface, but still, just out of curiosity, I’d be glad to know more about it.

  • 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-24T01:59:18+00:00Added an answer on May 24, 2026 at 1:59 am

    You don’t need to implement IParserAccessor to get functionality like what you are talking about. Instead create a collection to hold the child controls (we’ll call it Items) in your server control and apply the ParseChildren attribute to your server control with “Items” as the DefaultProperty value.

    The following link contains an example on how to implement ParseChildren:
    http://msdn.microsoft.com/en-us/library/aa310907(v=vs.71).aspx

    Update
    Information on IParserAccessor :

    From: http://msdn.microsoft.com/en-us/library/system.web.ui.iparseraccessor.aspx

    Because the Control class implements this interface, it is easier to
    extend that class and override its implementation of the
    AddParsedSubObject method than to implement this interface yourself.

    From: http://forums.asp.net/t/879797.aspx/1 (see imagemaker’s post):

    AddParsedSubObject is the only method of the IParserAccessor
    interface. The IParserAccessor interface is implemented by Control and
    all classes inheriting from Control as well as the ListItem class.
    When child controls or elements of server controls that implement the
    IParserAccessor interface are parsed from the HTML, the
    AddParsedSubObject method is called with the following method
    signature follows:

    VB — Sub AddParsedSubObject(ByVal obj As Object)
    C# — void AddParsedSubObject(object obj)

    The obj parameter represents the Object
    that has been parsed. In your custom server controls overridden
    AddParsedSubObject method, you can then check the type of obj then
    cast and process it accordingly, for example as a literal control or
    as a specific child element, by adding it to a child controls
    collection, item collection or whatever.

    Here is an examle from the same post:

    Where I first ran into dealing with implementing the IParserAccessor
    interface and the AddParsedSubObject was in defining the class for a
    child element that needed to contain as its inner content a string:

    <WESNet:StyledList id="StyledList1" runat="server">    
    <WESNet:StyledItem Value="2" ForeColor="red">Two</WESNet:StyledItem>  
    <WESNet:StyledItem Value="5"
    ForeColor="green">Five</WESNet:StyledItem></WESNet:StyledList>Because
    

    my StyledItem class did not inherit from Control, I had to implement
    IParserAccessor and its AddParsedSubObject as follows:

    Protected Sub AddParsedSubObject(ByVal obj As Object) Implements IParserAccessor.AddParsedSubObject
       If TypeOf obj Is LiteralControl Then
             Me.Text = CType(obj, LiteralControl).Text
       Else
            Throw New ArgumentException("Inner content of StyledItem must contain only static text")
       End If
    End Sub
    

    Then, in my StyledList class (which inherited from WebControl), I needed to override its
    AddParsedSubObject method as follows:

    Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)
       If TypeOf obj Is StyledItem Then
             Dim si As StyledItem = CType(obj, StyledItem)
             Items.Add(si)
       Else
             Throw New ArgumentException ("A StyledList server control may contain only StyledItems")
       End If
    End Sub
    

    Here, after checking that obj is a StyledItem, it is added to the
    Items collection of the control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a custom control in ASP.NET MVC. The thing that I
I'm trying to write a custom rendering template for use in the DisplayForm of
I'm trying to write a template for my control, SuperTextB, that set a rectangle
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
I'm trying to write a regex function that will identify and replace a single
I'm trying to write a custom WPF ValidationRule to enforce that a certain property
I'm trying to write a stored procedure to select employees who have birthdays that
I'm trying to write a custom inclusion_tag in django. Following the example on http://docs.djangoproject.com/en/dev/howto/custom-template-tags/
I'm trying to figure out how to write this function: template <typename Bound> Bound::result_type
I'm trying write a query to find records which don't have a matching record

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.