次の方法で共有


LinkButton.RenderContents メソッド

コントロールの内容を指定したライタに出力します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Protected Friend Overrides Sub RenderContents ( _
    writer As HtmlTextWriter _
)
'使用
Dim writer As HtmlTextWriter

Me.RenderContents(writer)
protected internal override void RenderContents (
    HtmlTextWriter writer
)
protected public:
virtual void RenderContents (
    HtmlTextWriter^ writer
) override
protected void RenderContents (
    HtmlTextWriter writer
)
protected internal override function RenderContents (
    writer : HtmlTextWriter
)
適用できません。

パラメータ

  • writer
    HTML コンテンツをクライアントに表示する出力ストリームを表す HtmlTextWriter

解説

このメソッドは、主にコントロールの開発者によって使用されます。

使用例

カスタム サーバー コントロールの RenderContents メソッドをオーバーライドして、LinkButton にテキストを追加する方法を次のコード例に示します。

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Custom LinkButton - RenderContents - VB.NET Example</title>
        <script runat="server">
            Sub LinkButton1_Command(sender As Object, e As CommandEventArgs)
                ' Redirect to the Microsoft home page.
                Response.Redirect("https://www.microsoft.com/")
            End Sub
        </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom LinkButton - RenderContents - VB.NET Example</h3>
            
            <aspSample:CustomLinkButtonRenderContents id="LinkButton1" 
             runat="server" OnCommand="LinkButton1_Command" 
             ToolTip="Microsoft Home">Microsoft Corp.</aspSample:CustomLinkButtonRenderContents>

        </form>
    </body>
</html>
...

    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomLinkButtonRenderContents
        Inherits System.Web.UI.WebControls.LinkButton

        Protected Overrides Sub RenderContents(ByVal writer As System.Web.UI.HtmlTextWriter)

            ' Call the base RenderContents method.
            MyBase.RenderContents(writer)

            ' Append some text to the LinkButton.
            writer.Write(" Home Page")
        End Sub
    End Class
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Custom LinkButton - RenderContents - C# Example</title>
    <script runat="server">
      void LinkButton1_Command(Object sender, CommandEventArgs e) 
      {
        // Redirect to the Microsoft home page.
        Response.Redirect("https://www.microsoft.com/");
      }
    </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom LinkButton - RenderContents - C# Example</h3>
            
            <aspSample:CustomLinkButtonRenderContents 
              id="LinkButton1" 
              runat="server" 
              OnCommand="LinkButton1_Command" 
              ToolTip="Microsoft Home">Microsoft Corp.
            </aspSample:CustomLinkButtonRenderContents>

        </form>
    </body>
</html>
...

using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomLinkButtonRenderContents : System.Web.UI.WebControls.LinkButton
  {
    protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
    {
      // Call the base RenderContents method.
      base.RenderContents(writer);

      // Append some text to the LinkButton.
      writer.Write(" Home Page");
    }
  }
}
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Custom LinkButton - RenderContents - VJ# Example</title>
    <script runat="server">
        void LinkButton1_Command(Object sender, CommandEventArgs e) 
        {
            // Redirect to the Microsoft home page.
            get_Response().Redirect("https://www.microsoft.com/");
        } //LinkButton1_Command
    </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom LinkButton - RenderContents - VJ# Example</h3>
            
            <aspSample:CustomLinkButtonRenderContents 
              id="LinkButton1" 
              runat="server" 
              OnCommand="LinkButton1_Command" 
              ToolTip="Microsoft Home">Microsoft Corp.
            </aspSample:CustomLinkButtonRenderContents>

        </form>
    </body>
</html>
...

package Samples.AspNet.JSL.Controls; 

public class CustomLinkButtonRenderContents
    extends System.Web.UI.WebControls.LinkButton
{
    protected void RenderContents(System.Web.UI.HtmlTextWriter writer)
    {
        // Call the base RenderContents method.
        super.RenderContents(writer);
        // Append some text to the LinkButton.
        writer.Write(" Home Page");
    } //RenderContents
} //CustomLinkButtonRenderContents

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

LinkButton クラス
LinkButton メンバ
System.Web.UI.WebControls 名前空間
HtmlTextWriter

その他の技術情報

Button Web サーバー コントロール