views:

46

answers:

1

I know that people have had some trouble with undefined CssClass values when using partial classes in ASP.NET MVC. My project is not MVC, however, and I am including a .css file that is in the root folder of my project, yet a referenced class value still results in a warning in VS 2008.

In my .aspx file:

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <!-- ... -->
        <link media="all" href="~MyStyles.css" type="text/css" rel="stylesheet" />
    </head>
    <body id="bodyTag" vlink="#666666" alink="#666666" link="#666666" bgcolor="#ffffff" leftmargin="0" topmargin="0" runat="server">
        <script type="text/javascript" language="javascript" src="~Scripts\Somecript_v1.js"></script>
        <!-- form, table ... -->
                <asp:TableRow>
                    <asp:TableCell ColumnSpan="4" CssClass="cellclass">  

Then, in the same folder as the .aspx, in "MyStyles.css", I have defined:

.cellclass
{
    border-right: #aeaeae 1px solid;
    border-top: #aeaeae 1px solid;
    font-weight: normal;
    font-size: 11px;
/* etc. */  

Yet I get the warning, "The class or CssClass value is not defined".

+1  A: 

Your problem is with this line:

<link media="all" href="~MyStyles.css" type="text/css" rel="stylesheet" />

You cannot use the ~ syntax in non runat="server" controls. You can't use it in link or script tags anyway. So your href should look like:

<link media="all" href="MyStyles.css" type="text/css" rel="stylesheet" />

For security, in case you move the file aspx file later you would be advised to include the full path from the root of the website starting with a / e.g. /MyFolder/MyStyles.css

Philip Smith
When I remove the tilde, I get the warning "File 'mystyles.css' was not found."
Buggieboy
Then you need to include the path. Without path info ASP.NET looks for the file in the root of the website not the folder the aspx file is in. Add a path to the href or move the stylesheet to the root of the website.
Philip Smith
If I'm building a new app in VS 2008, under Win 7, the project is created in C:\Users\myname\Documents\Visual Studio 2008\Projects\myproject. I haven't deployed yet, so I really don't know what you mean by "the root of the website", and I don't know what the href path would be relative to.
Buggieboy
The root of the website would be where the web.config lives. In your case most likely the myproject folder.
Philip Smith
Okay, so I verified that the stylesheet is in the same folder as the web.config. Changed the reference to look like this:<link media="all" href="./MyStyles.css" type="text/css" rel="stylesheet" />yet get the same "not defined" error.
Buggieboy
You don't need the dot in the path. The dot means "here" so "./MyStyles.css" is the same as "MyStyles.css". What you need to say is "from the root" which is "/MyStyles.css.
Philip Smith