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. 元素和style專案會加入至頁面的head元素。 titleA 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>

備註

屬性會取得HtmlHead物件的參考, 您可以用來設定頁面的檔標頭資訊。 HeaderThe Header property gets a reference to an HtmlHead object that you can use to set document header information for the page. 可讓您將樣式表單、樣式規則、標題和中繼資料等資訊新增head至專案。 HtmlHeadThe 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.

適用於

另請參閱