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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:56:00+00:00 2026-06-04T06:56:00+00:00

In asp.net, if you use a custom attribute, usually it is rendered as-is. Considering

  • 0

In asp.net, if you use a custom attribute, usually it is rendered as-is.

Considering this markup (note: attributes such as id, name and for were removed in all examples as their generated id/names are verbose):

<asp:TextBox runat="server" data-foo="bar" />

Is rendered in asp.net as:

<input type="text" data-foo="bar" />

That is, asp.net keeps data-foo untouched.

Check box are usually rendered like this:

<asp:CheckBox runat="server" Text="Normal" />

Renders as:

<input type="checkbox" />
<label>Normal</label>

But if you add a custom attribute on a checkbox:

<asp:CheckBox runat="server" Text="Custom attribute" data-foo="bar"  />

It renders as:

<span data-foo="bar">
    <input type="checkbox" />
    <label>Custom attribute</label>
</span>

As you can see, a span in rendered to hold the attribute. This also happens if you add the attribute in code behind. This does not happen with any other HtmlControl, AFAIK.

Does anyone know why this span is rendered to hold the attribute?

Is there anyway to render the attribute in the input tag?

  • 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-06-04T06:56:01+00:00Added an answer on June 4, 2026 at 6:56 am

    I’m not sure why it’s rendered with a span, but I suppose you can add the attribute directly to the input element of the CheckBox in code-behid like this:

    myCheckBox.InputAttributes.Add(...)
    

    Reference links:

    • http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.inputattributes.aspx
    • http://forums.asp.net/p/541142/541562.aspx
    • http://msdn.microsoft.com/en-us/library/system.web.ui.attributecollection.add.aspx

    Update

    An additional parent element is used, so that the attributes you apply to a CheckBox can affect both the input and the text. I suppose it’s a span (and not a div), because it’s an inline element, making it more convenient to use in different scenarios.

    Reference links:

    • http://en.wikipedia.org/wiki/Span_and_div#Differences_and_default_behavior
    • http://learnwebdesignonline.com/span-div
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is VS 2008 and .Net 3.5. I use a custom deployment project script
I am working on two ASP.NET websites. Both use custom authentication process based on
I have two custom attributes in my asp.net mvc(C#) application. [CustAttribute1()] [CustAttribute2()] When I
I want to create a custom asp.net mvc3 helper . To use that helper,
I have made custom attribute in my asp.net mvc2 project: [AttributeUsage(AttributeTargets.Property, AllowMultiple = false,
I use a custom-built asp.net control that renders to a DIV and has height='0'
I notice a lot of the examples for ASP.NET use Linq2Sql as the datasource.
In ASP.NET we use async methods because the Thread Pool has limited slots, and
I want to use ASP.NET and IIS to download dynamically generated files to the
I want to use ASP.Net on Linux because of license problems and costs. Can

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.