How to set a custom attribute to asp.net literal and read it in code behind? There's no Attributes collection.
A Literal isn't a HTML element, it literally is a literal (sorry for that). Its content becomes verbatim output in the response so there are no attributes to pull.
Attributes on ASP.NET controls are properties of the control class so you could try descending from Literal and defining your own property.
Just because some may map to HTML attributes is purely chance as they're only relevant to the server when rendering the page usually, the control dictates what output actually happens and how the properties map to the attributes.
If you want a generic HTML element you can try HtmlGenericControl which should offer the basic HTML properties for you to play with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With