开发者

CssClass value not found for non-MVC ASP.NET form

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" r开发者_如何学编程unat="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".


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜