WebControl クラス
アセンブリ: System.Web (system.web.dll 内)
構文
WebControl クラスには、すべての Web サーバー コントロールに共通するプロパティ、メソッド、およびイベントが用意されています。このクラスで定義されたプロパティを設定することによって、Web サーバー コントロールの外観と動作を制御できます。たとえば、コントロールの背景色とフォントの色を制御するには、BackColor プロパティと ForeColor プロパティをそれぞれ設定します。境界線を表示できるコントロールで、境界線の幅、境界線スタイル、および境界線の色を制御するには、BorderWidth、BorderStyle、BorderColor の各プロパティをそれぞれ設定します。Web サーバー コントロールのサイズを指定するには、Height プロパティと Width プロパティを使用します。
コントロールの動作は、特定のプロパティを設定して指定できます。コントロールを有効または無効にするには、Enabled プロパティを設定します。タブ オーダーのコントロールの位置を制御するには、TabIndex プロパティを設定します。コントロールのツールヒントを指定するには、ToolTip プロパティを設定します。
メモ |
---|
このクラスで定義されるプロパティを一部しかサポートしないコントロールもあります。プロパティがサポートされるかどうかについては、特定のコントロールに関するドキュメントを参照してください。 |
メモ |
---|
このクラスのプロパティの中には、ブラウザによって表示方法が異なるプロパティがあります。まったく表示されないプロパティもあれば、表示には影響を与えないプロパティもあります。HttpBrowserCapabilities オブジェクトの TagWriter プロパティによって、Web サーバー コントロールでの表示方法を決定します。HTML 4.0 をサポートするブラウザの場合、TagWriter プロパティは通常の HttpBrowserCapabilities オブジェクトを示し、ほとんどのプロパティは HTML 4.0 スタイル属性を使用して表示されます。HTML 4.0 をサポートすることが認識されないブラウザは、Html32TextWriter オブジェクトを使用します。これによって、スタイル属性は、関連の HTML 3.2 タグ属性に自動的に変換されます。ForeColor プロパティを使用した場合などに、スタイル属性が、<font> タグなどの追加のタグに変換される場合があります。また、マップが実行されない場合もあります。プロパティを各種ブラウザに表示する方法については、特定のプロパティに関するドキュメントを参照してください。 |
WebControl のインスタンスの初期プロパティ値の一覧については、WebControl コンストラクタのトピックを参照してください。
Imports System Imports System.Web.UI Imports System.Web.UI.WebControls Namespace ControlTest ' Renders the following HTML: ' <span onclick="alert('Hello');" style="color:Red;">Custom Contents</span> Public Class MyWebControl Inherits WebControl Public Sub New() MyBase.New(HtmlTextWriterTag.Span) End Sub 'New <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Protected Overrides Sub AddAttributesToRender(writer As HtmlTextWriter) writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');") writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red") MyBase.AddAttributesToRender(writer) End Sub 'AddAttributesToRender <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Protected Overrides Sub RenderContents(writer As HtmlTextWriter) writer.Write("Custom Contents") MyBase.RenderContents(writer) End Sub 'RenderContents End Class 'MyWebControl End Namespace 'ControlTest
namespace ControlTest { using System; using System.Web.UI; using System.Web.UI.WebControls; // Renders the following HTML: // <span onclick="alert('Hello');" style="color:Red;">Custom Contents</span> public class MyWebControl: WebControl { public MyWebControl() : base(HtmlTextWriterTag.Span) { } [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] protected override void AddAttributesToRender(HtmlTextWriter writer) { writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');"); writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red"); base.AddAttributesToRender(writer); } [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] protected override void RenderContents(HtmlTextWriter writer) { writer.Write("Custom Contents"); base.RenderContents(writer); } } }
package ControlTest; import System.*; import System.Web.UI.*; import System.Web.UI.WebControls.*; // Renders the following HTML: // <span onclick="alert('Hello');" style="color:Red;">Custom Contents</span> public class MyWebControl extends WebControl { public MyWebControl() { super(HtmlTextWriterTag.Span); } //MyWebControl protected void AddAttributesToRender(HtmlTextWriter writer) { writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');"); writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red"); super.AddAttributesToRender(writer); } //AddAttributesToRender /** @attribute System.Security.Permissions.PermissionSet(System.Security. Permissions.SecurityAction.Demand, Name = "FullTrust") */ protected void RenderContents(HtmlTextWriter writer) { writer.Write("Custom Contents"); super.RenderContents(writer); } //RenderContents } //MyWebControl
スレッド セーフ
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- WebControl クラスのページへのリンク