Sometimes you have classes in your HTML that are not in your CSS for one reason or another.  Maybe they are only used in your JavaScript.  If you are tired of Visual Studio giving you the warning "The class or CssClass value is not defined," there is a way to suppress it.  Here's my solution:

First, add the following to the head element in your HTML document:

<head runat="server">
  <title>The Page</title>
  <asp:Literal Visible="false" runat="server">
    <link href="~/Content/SuppressCssWarnings.css" rel="stylesheet" type="text/css" />
  </asp:Literal>
  <!-- You probably have more here... -->
</head>

Notice, a few things here.  First, that there is a runat="server" in the head.  This is important for the ~ to work correctly.  I also think you need it in order to have any <asp: ...> control in the head.  The next thing to notice is the css file that has been added.  This is where you add all the classes that Visual Studio is warning you about.  Just cut and paste, it's not that bad.  Finally, see how the link to your stylesheet is inside the asp Literal control?  That keeps it from showing up in your rendered page.

Inside the SuppressCssWarnings.css file is just a list of your classes like so:

/* The whole point of this css is to get VS off my back.  I'm sick of its "The class or CssClass value is not defined." */
.yui-skin-sam {}
.yuimenubar {}
.yuimenubarnav {}
.bd {}
.yuimenubaritem {}
.first-of-type {}
.yuimenubaritemlabel {}
.yuimenu {}
.yuimenuitem {}

And that's it!  Good luck!  As you can see I've been working with YUI recently.  Check it out, it's a good JavaScript library, and it should work especially well the the ASP.NET MVC Framework.

posted on Sunday, March 23, 2008 4:32 AM |

Comments

5/12/2008 10:32 AM

Extending what you have done here, for User Controls, this works nicely:

<link href="~/App_Themes/Main/Default.css" rel="stylesheet" type="text/css" runat="server" Visible="false" />

5/13/2008 9:55 AM

Nice one! I like it.

7/24/2008 11:26 AM

Not necessary. You can turn it off in VS 2005 and VS 2008 options (TextEditor --> CSS) Depending on your VS version it's under CSS Specific or Validation. Uncheck the Detect Errors or the options you want for this.

7/28/2008 5:08 PM

Mike, thanks for that. I'll probably disable that most of the time. Although, I would still like to keep some error checking. Just not checking my class names. It would be nice if that was an option in Visual Studio.

8/25/2008 4:30 AM

Very nice.It resolved my bugs.

10/22/2008 2:24 PM

Did not realy solve the problem, just suppressed it

11/4/2008 7:40 AM

Hi,
I'm writing a blog entry about cssClass problems in Visual Studio 2008 and would like to reference you and your solution in "Tired of Visual Studio Telling You "The class or CssClass value is not defined"?" in my article as a partial solution for that problem. You can read it at my blog: http://schprit.blogspot.com/
If you have a problem with me using it or referencing you, please write me an email.
Comments have been closed on this topic.