Page.Header プロパティ

定義

ページの宣言で head 要素が runat=server を使用して定義されている場合に、ドキュメントのヘッダーを取得します。

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; }
[<System.ComponentModel.Browsable(false)>]
member this.Header : System.Web.UI.HtmlControls.HtmlHead
Public ReadOnly Property Header As HtmlHead

プロパティ値

ページ ヘッダーを格納している HtmlHead

属性

次のコード例では、 プロパティを使用してプログラムでコントロールにアクセス HtmlHead する方法を Header 示します。 title要素と style 要素がページのhead要素に追加されます。

<%@ 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 設定するために使用できるオブジェクトへの参照を取得します。 HtmlHeadでは、スタイル シート、スタイル ルール、タイトル、メタデータなどの情報を 要素にhead追加できます。

Note

非同期ポストバック中にインターフェイスのメソッドを IStyleSheet 使用してプログラムでスタイルを追加することはサポートされていません。 AJAX 機能を Web ページに追加すると、ページ全体を更新することなく、非同期ポストバックによってページの更新領域が更新されます。 詳細については、「Microsoft Ajax の概要」を参照してください。

適用対象

こちらもご覧ください