Showing posts with label Visual Studio 2008. Show all posts
Showing posts with label Visual Studio 2008. Show all posts

通常在 MasterPage 中會引用一些 CSS,但是很詭異的是在 ContentPlaceHolder 使用那些定義於 CSS 中的 class 時,儘管實際 render 網頁的時候是正確的,但每次看到編譯完後 MS Visual Studio 2008 出現一排警告訊息還是覺得很厭煩...
MS-VS-class-error

雖然有網友說安裝完 VS SP1 後就可以解決上述的問題,不過在我的開發環境還是一樣會出現這些警告訊息;下列的程式碼是從 Tired of Visual Studio Telling You "The class or CssClass value is not defined"? 擷取出來的,原作者把原本的引用路徑複製一份到 <asp: Literal...> 中,且把該控制項設定為 Visible="false",編譯後檢視網頁原始碼會發現並沒有什麼不同(因為 Visible="false"),但是對 Visual Studio 而言就不會出現那些警告訊息了,雖然不是最佳解,但還是有蠻好的效果的。

<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... -->
  <link href="~/Content/SuppressCssWarnings.css"
      rel="stylesheet" type="text/css" />
</head>