In ASP.NET, you can add custom HTML tag attributes to a UserControl via
myLabel.Attributes['my-custom-attribute'] = "someValue";
// or Attributes.Add()
… but how can I add an attribute that doesn’t have a value? For example, (and I’m not saying that this is what I need) the W3C specification only needs the checked attribute present in a checkbox to consider it checked (instead of checked='true' or something).
<span ID="ctl-blah-blah-myLabel" my-custom-attribute>some text</span>
I’m looking into using something like this to tag specific elements on my page for some client-side behavior. I know that I can do the same with classes, but (1) classes are iffy to manipulate server-side, and (2) I kind of don’t want to pollute my class declarations just for tagging (that may be weird for some, I know).
I don’t think you can, doing what you’re asking is not a well-formed document. The W3C specification you are looking at is old, as far as the
checkedattribute is concerned. Proper form, now-a-days, is to put checked=”checked”.While many browsers might accept this, I wouldn’t recommend that you do it. What is it that you’re trying to accomplish? Maybe there’s a better solution.