2009-10-07 61 views

回答

5

我這樣做了一次,在母版頁中添加了一個標題佔位符,並在內容頁中明確指定了css。

在站長:

<head runat="server"> 
    <title></title> 
    <link href="~/css/common.css" rel="stylesheet" type="text/css" /> 
    <!-- loads of other stuff/--> 
    <asp:ContentPlaceHolder ID="head" runat="server"> 
    </asp:ContentPlaceHolder> 
</head> 

和內容:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
     <link href="../css/SomeContent.css" rel="stylesheet" type="text/css" /> 
     <script src="../js/SomeJsToo.js" type="text/javascript"></script> 
</asp:Content> 
+0

你是什麼意思「一個標題佔位符」? – dani 2009-10-07 14:40:35

+0

內容佔位符:http://www.asp.net/Learn/master-pages/tutorial-02-vb.aspx – b0x0rz 2009-10-07 14:42:50

+1

對不起,沒有足夠的解釋。我添加了一個例子。 – Nils 2009-10-07 14:47:49

0

使用使用的所有頁面上外部主CSS文件:

<link rel="stylesheet" type="text/css" href="master.css" /> 

然後你可以使用嵌入式使用樣式標籤在各個內容頁上使用CSS,例如:

<style type="text/css"> 
h1 {color:red} 
p {color:blue} 
</style> 
1

如果您使用的是visual studio 2008,那麼您將擁有一個真正簡單的時間。首先做一個母版頁是這樣的:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <asp:ContentPlaceHolder id="head" runat="server"> 
    </asp:ContentPlaceHolder> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> 

     </asp:ContentPlaceHolder> 
    </div> 
    </form> 
</body> 
</html> 

現在讓基於關閉該母版頁的內容頁:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 
</asp:Content> 

現在,在內容1佔位符,你只需將你想擁有樣式表應用於該頁面。

就是這樣。希望這對你有用。

0

我已經嘗試了許多上述方法,但仍然出現錯誤。最後我在頁面加載中使用以下代碼,它工作正常:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    Dim css1 As New HtmlLink 
    css1.Href = ResolveUrl("report.css") 
    css1.Attributes("rel") = "stylesheet" 
    css1.Attributes("type") = "text/css" 
    css1.Attributes("media") = "all" 
    Me.Page.Header.Controls.Add(css1) 

End Sub