I’ve been working on someone’s project and noticed Visual Studio produces a message for each ASP tag that has a class attribute. For example:
Attribute ‘class’ is not a valid attribute of element ‘TextBox’.
If I visit the website, it seems to work correctly. An example that produces the message looks like this:
<asp:TextBox class="makeInline loginItem" ID="UserName" runat="server"></asp:TextBox>
On the website it becomes this:
<input type="text" class="makeInline loginItem" id="Login1_UserName" name="Login1$UserName">
So it looks like the class attribute gets carried over to the HTML tag. Is this fine, or is there a better way to do this?
Server controls use
CssClassinstead ofclass(presumably to avoid ambiguity over the meaning ofclass).Unknown attributes will be carried over. But while it works in this case, use the attributes that the control expects whenever possible. ASP.Net will occasionally alter the markup to “correct” it. Example: valid HTML 5 input type attributes (e.g.
type="number") were “corrected” when the control was rendered until a fix was released to correct the problem.You can place a custom attribute (e.g.
data-*) on a server tag without concern.This does not cause a validation error in Visual Studio 2012, and renders as expected.