Reputation: 44105
How to set a custom attribute to asp.net literal and read it in code behind? There's no Attributes collection.
Upvotes: 3
Views: 2438
Reputation: 29668
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.
Upvotes: 3