次の方法で共有


AttributeCollection.Render メソッド

指定した HtmlTextWriter 出力ストリームに属性のコレクションを書き込みます。その後、出力ストリームは、そのコレクションが属する ASP.NET サーバー コントロールにそのコレクションを書き込みます。

Public Sub Render( _
   ByVal writer As HtmlTextWriter _)
[C#]
public void Render(HtmlTextWriterwriter);
[C++]
public: void Render(HtmlTextWriter* writer);
[JScript]
public function Render(
   writer : HtmlTextWriter);

パラメータ

  • writer
    属性コレクションを現在の出力ストリームの位置に書き込む HtmlTextWriter オブジェクト。

使用例

[Visual Basic, C#, C++] Render メソッドを使用する例を次に示します。

 
' Create a custom WebControl class, named AttribRender, that overrides 
' the Render method to write two introductory strings. Then call the
' AttributeCollection.Render method, which allows the control to write the
' attribute values that are added to it when it is included in a page.
' This sample can be used as a code-behind file for a .aspx file.
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls

' Create the namespace that contains the AttribRender and the
' page that accesses it.
Namespace AC_Render

 ' This is the custom WebControl class.
 Public Class AttribRender
   Inherits WebControl
   
   ' This is the overridden WebControl.Render method.
   Protected Overrides Sub Render(output As HtmlTextWriter)
      output.Write("<h2>An AttributeCollection.Render Method Example</h2>")
      output.Write("The attributes, and their values, added to the ctl1 control are <br><br>")
      ' This is the AttributeCollection.Render method call. When the
      ' page that contains this control is requested, the
      ' attributes that the page adds, and their values,
      ' are rendered to the page.
      Attributes.Render(output)
   End Sub 'Render
 End Class 'AttribRender

' This is the page code that adds attributes to the AttribRender class.
 Public Class RenderAttribs
   Inherits Page
   
   Sub Page_Load(sender As Object, e As EventArgs)
      ' Create an instance of AttribRender and name it ctl1.
      Dim ctl1 As New AttribRender()
      ' Add attributes to ctl1. When the page is requested,
      ' these attributes will be rendered to the page.
      ctl1.Attributes.Add("Text", "HelloWorld!")
      ctl1.Attributes.Add("Attribute1", "The value for Attribute1.")
      Controls.Add(ctl1)
   End Sub 'Page_Load
 End Class 'RenderAttribs
End Namespace 'AC_Render

[C#] 
/* Create a custom WebControl class, named AttribRender, that overrides 
   the Render method to write two introductory strings. Then call the
   AttributeCollection.Render method, which allows the control to write the
   attribute values that are added to it when it is included in a page.
   This sample can be used as a code-behind file for a .aspx file.
*/
   
using System;
using System.Web.UI;
using System.Web.UI.WebControls;

// Create the namespace that contains the AttribRender and the
// page that accesses it.
namespace AC_Render
{
   // This is the custom WebControl class.
   public class AttribRender : WebControl
   {
      // This is the overridden WebControl.Render method.
      protected override void Render(HtmlTextWriter output)
      {
         output.Write("<h2>An AttributeCollection.Render Method Example</h2>");
         output.Write("The attributes, and their values, added to the ctl1 control are <br><br>");
         // This is the AttributeCollection.Render method call. When the
         // page that contains this control is requested, the
         // attributes that the page adds, and their values,
         // are rendered to the page.
         Attributes.Render(output);
      }
   }

   // This is the page code that adds attributes to the AttribRender class.
   public class RenderAttribs : Page
   {
      void Page_Load(object sender, EventArgs e)
      {
         // Create an instance of AttribRender and name it ctl1.
         AttribRender ctl1 = new AttribRender();
         // Add attributes to ctl1. When the page is requested,
         // these attributes will be rendered to the page.
         ctl1.Attributes.Add("Text","HelloWorld!");
         ctl1.Attributes.Add("Attribute1","The value for Attribute1.");
         Controls.Add(ctl1);
      }
   }
}

[C++] 
/* Create a custom WebControl class, named AttribRender, that overrides 
   the Render method to write two introductory strings. Then call the
   AttributeCollection.Render method, which allows the control to write the
   attribute values that are added to it when it is included in a page.
   This sample can be used as a code-behind file for a .aspx file.
*/
   
#using <mscorlib.dll>
#using <System.Web.dll>
#using <System.dll>
using namespace System;
using namespace System::Web::UI;
using namespace System::Web::UI::WebControls;

// Create the namespace that contains the AttribRender and the
// page that accesses it.
namespace AC_Render
{
   // This is the custom WebControl class.
   public __gc class AttribRender : public WebControl
   {
      // This is the overridden WebControl.Render method.
   protected:
      void Render(HtmlTextWriter* output)
      {
         output->Write(S"<h2>An AttributeCollection.Render Method Example</h2>");
         output->Write(S"The attributes, and their values, added to the ctl1 control are <br><br>");
         // This is the AttributeCollection.Render method call. When the
         // page that contains this control is requested, the
         // attributes that the page adds, and their values,
         // are rendered to the page.
         Attributes->Render(output);
      }
   };

   // This is the page code that adds attributes to the AttribRender class.
   public __gc class RenderAttribs : public Page
   {
      void Page_Load(Object* /*sender*/, EventArgs* /*e*/)
      {
         // Create an instance of AttribRender and name it ctl1.
         AttribRender* ctl1 = new AttribRender();
         // Add attributes to ctl1. When the page is requested,
         // these attributes will be rendered to the page.
         ctl1->Attributes->Add(S"Text",S"HelloWorld!");
         ctl1->Attributes->Add(S"Attribute1",S"The value for Attribute1.");
         Controls->Add(ctl1);
      }
   };
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

参照

AttributeCollection クラス | AttributeCollection メンバ | System.Web.UI 名前空間 | HtmlControl.Attributes | HtmlTextWriter | WebControl.Attributes