Page.Header Page.Header Page.Header Page.Header Property

定義

取得頁面的文件標頭,如果在頁面宣告中使用 head 定義 runat=server 項目。Gets the document header for the page if the head element is defined with a runat=server in the page declaration.

public:
 property System::Web::UI::HtmlControls::HtmlHead ^ Header { System::Web::UI::HtmlControls::HtmlHead ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.HtmlControls.HtmlHead Header { get; }
member this.Header : System.Web.UI.HtmlControls.HtmlHead
Public ReadOnly Property Header As HtmlHead

屬性值

包含頁面標頭的 HtmlHeadAn HtmlHead containing the page header.

範例

下列程式碼範例示範如何存取HtmlHead控制以程式設計方式使用Header屬性。The following code example demonstrates how to access the HtmlHead control programmatically using the Header property. Atitle項目和style項目新增至head頁面項目。A title element and style element are added to the head element of the page.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">  
  
  protected void Page_Load(object sender, System.EventArgs e)
  {
      
      // Create a Style object for the body of the page.
      Style bodyStyle = new Style();

      bodyStyle.ForeColor = System.Drawing.Color.Blue;
      bodyStyle.BackColor = System.Drawing.Color.LightGray;

      // <Snippet2>
      // Add the style rule named bodyStyle to the header 
      // of the current page. The rule is for the body HTML element.
      Page.Header.StyleSheet.CreateStyleRule(bodyStyle, null, "body");
      // </Snippet2>
 
      // Add the page title to the header element.
      Page.Header.Title = "HtmlHead Example"; 
                   
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="head1"
      runat="server">
      <title>To be replaced.</title>
</head>

<body>
  <form id="form1" runat="server">
  
  <h3>HtmlHead Class Example</h3>  
    
  <asp:label id="Label1" 
    text = "View the HTML source code of this page to see the title 
            and body style added to the header element."
    runat="server">
  </asp:label>   
    
  </form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        
        ' Create a Style object for the body of the page.
        Dim bodyStyle As New Style()
        
        bodyStyle.ForeColor = System.Drawing.Color.Blue
        bodyStyle.BackColor = System.Drawing.Color.LightGray

        ' <Snippet2>
        ' Add the style rule named bodyStyle to the header 
        ' of the current page. The rule is for the body HTML element.
        Page.Header.StyleSheet.CreateStyleRule(bodyStyle, Nothing, "body")
        ' </Snippet2>
            
        ' Add the page title to the header element.
        Page.Header.Title = "HtmlHead Example"

    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="head1"
      runat="server">
      <title>To be replaced.</title>
</head>

<body>
  <form id="Form1" runat="server">
  
  <h3>HtmlHead Class Example </h3>  
    
  <asp:label id="Label1" 
    text = "View the HTML source code of this page to see the title 
            and body style added to the header element."
    runat="server">
  </asp:label>   
    
  </form>
</body>
</html>

備註

Header屬性取得的參考HtmlHead物件,您可以用來設定頁面的文件標頭資訊。The Header property gets a reference to an HtmlHead object that you can use to set document header information for the page. HtmlHead可讓您新增資訊,例如樣式表、 樣式規則、 標題和中繼資料,以head項目。The HtmlHead allows you to add information such as style sheets, style rules, a title, and metadata to the head element.

注意

新增樣式使用的方法,以程式設計方式IStyleSheet不支援非同步回傳期間的介面。Adding styles programmatically using the methods of the IStyleSheet interface during asynchronous postbacks is not supported. 當您將 AJAX 功能新增至網頁時,非同步回傳會更新網頁的區域,而不需要更新整個頁面。When you add AJAX capabilities to a Web page, asynchronous postbacks update regions of the page without updating the whole page. 如需詳細資訊,請參閱 < Microsoft Ajax 概觀For more information, see Microsoft Ajax Overview.

適用於

另請參閱