3

How to set a custom attribute to asp.net literal and read it in code behind? There's no Attributes collection.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.