Search code examples
asp.netlabelstylesheetexternal

How to acces asp label controls from external stylesheets


I was trying to style asp Label controls from external StyleSheet.

To my surprise, unlike img, input[type='text'], input[type='button'] etc that works on asp image, textbox, button controls respectively,

the styles are not being applied to the label controls..!

how is asp label rendered as html?

Does anyone know how to refer to all label controls from external style sheets, other than manually specifying a css class for each of them or using inline styles...?


Solution

  • I presume you mean ASP.NET not Classic ASP, right?

    asp:Label controls get rendered differently depending on whether they have AssociatedControlID set or not.

    If AssociatedControlID is set they get rendered as a label HTML element.

    If AssociatedControlID is not set they get rendered as a span HTML element.

    It is good practice for accessibility and other reasons to always include an AssociatedControlID if the label control relates to an input control.