Make ASP.NET Label render as HTML Label tag

By default the <asp:Label /> control in ASP.NET render as a <span> HTMl tag. That can be kind of a problem if you have some CSS that only applies to an <label> tag. So, how do you make a <asp:label /> render as a <label> tag?

Actually it’s pretty easy. All you need to to is to set the “AssociatedControlID” on the <asp:Label /> to an associated text. The reason for this is that you usually use a label as the caption for a textbox, as it is the nature of the HTML <label> tag.