ControlIDConverter クラス
アセンブリ: System.Web (system.web.dll 内)


ControlIDConverter クラスは StringConverter クラスから派生し、デザイン時環境でプロパティのグリッド コントロールに表示されるコントロール ID のリストを提供します。ControlIDConverter クラスは、Web コントロールの型コンバータである AssociatedControlConverter クラスと、検証プロパティの属性をサポートするコントロールの型コンバータである ValidatedControlConverter クラスの基本クラスとしても機能します。

コントロール ID の表示を TypeConverter に対して要求するクラス内で ControlIDConverter を使用する方法のコード例を次に示します。DebugInfoControl は、現在の Web フォームに格納されているコントロールの一部の情報を印刷する単純なコントロールです。その ControlID プロパティは、ControlIDConverter をそのプロパティで使用する TypeConverter として指定する TypeConverterAttribute で装飾されています。DebugInfoControl は Render メソッドをオーバーライドして、Label コントロール内の対象のコントロールに関する情報を印刷します。
Imports System Imports System.ComponentModel Imports System.Web.UI Imports System.Web.UI.WebControls Namespace Samples.AspNet.VB <DefaultProperty("ControlID")> _ Public Class DebugInfoControl Inherits Control Public Sub New() End Sub 'New Public Sub New(controlID As String) ControlID = controlID End Sub 'New <DefaultValue(""), TypeConverter(GetType(ControlIDConverter))> _ Public Property ControlID() As String Get Dim o As Object = ViewState("ControlID") If o Is Nothing Then Return String.Empty End If Return CStr(o) End Get Set If ControlID <> value Then ViewState("ControlID") = value End If End Set End Property Protected Overrides Sub Render(writer As HtmlTextWriter) Dim info As New Label() If Me.ControlID.Length = 0 Then writer.Write("<Font Color='Red'>No ControlID set.</Font>") End If Dim ctrl As Control = Me.FindControl(ControlID) If ctrl Is Nothing Then writer.Write(("<Font Color='Red'>Could not find control " + ControlID + " in Naming Container.</Font>")) Else writer.Write(("<Font Color='Green'>Control " + ControlID + " found.<BR>")) writer.Write(("Its Naming Container is: " + ctrl.NamingContainer.ID + "<BR>")) If ctrl.EnableViewState Then writer.Write("It uses view state to persist its state.<BR>") End If If ctrl.EnableTheming Then writer.Write("It can be assigned a Theme ID.<BR>") End If If ctrl.Visible Then writer.Write("It is visible on the page.<BR>") Else writer.Write("It is not visible on the page.<BR>") End If writer.Write("</Font>") End If End Sub 'Render End Class 'DebugInfoControl End Namespace
namespace Samples.AspNet.CS { using System; using System.ComponentModel; using System.Web.UI; using System.Web.UI.WebControls; [DefaultProperty("ControlID")] public class DebugInfoControl : Control { public DebugInfoControl() { } public DebugInfoControl(string controlID) { ControlID = controlID; } [DefaultValue(""), TypeConverter(typeof(ControlIDConverter))] public string ControlID { get { object o = ViewState["ControlID"]; if (o == null) return String.Empty; return (string)o; } set { if (ControlID != value) { ViewState["ControlID"] = value; } } } protected override void Render(HtmlTextWriter writer) { Label info = new Label(); if (this.ControlID.Length == 0) { writer.Write("<Font Color='Red'>No ControlID set.</Font>"); } Control ctrl = this.FindControl(ControlID); if (ctrl == null) { writer.Write("<Font Color='Red'>Could not find control " + ControlID + " in Naming Container.</Font>"); } else { writer.Write("<Font Color='Green'>Control " + ControlID + " found.<BR>"); writer.Write("Its Naming Container is: " + ctrl.NamingContainer.ID + "<BR>"); if (ctrl.EnableViewState) writer.Write("It uses view state to persist its state.<BR>"); if (ctrl.EnableTheming) writer.Write("It can be assigned a Theme ID.<BR>"); if (ctrl.Visible) writer.Write("It is visible on the page.<BR>"); else writer.Write("It is not visible on the page.<BR>"); writer.Write("</Font>"); } } } }
package Samples.AspNet.JSL ; import System.*; import System.ComponentModel.*; import System.Web.UI.*; import System.Web.UI.WebControls.*; /** @attribute DefaultProperty("ControlID") */ public class DebugInfoControl extends Control { public DebugInfoControl() { } //DebugInfoControl public DebugInfoControl(String controlID) { set_ControlID(controlID); } //DebugInfoControl /** @attribute DefaultValue("") * @attribute TypeConverter(ControlIDConverter.class) */ /** @property */ public String get_ControlID() { Object o = get_ViewState().get_Item("ControlID"); if (o == null) { return ""; } return (String)(o); }//get_ControlID /** @property */ public void set_ControlID(String value) { if (!(get_ControlID().Equals(value))) { get_ViewState().set_Item("ControlID", value); } }//set_ControlID protected void Render(HtmlTextWriter writer) { Label info = new Label(); if (this.get_ControlID().length() == 0) { writer.Write("<Font Color='Red'>No ControlID set.</Font>"); } Control ctrl = this.FindControl(get_ControlID()); if (ctrl == null) { writer.Write(("<Font Color='Red'>Could not find control " + get_ControlID() + " in Naming Container.</Font>")); } else { writer.Write(("<Font Color='Green'>Control " + get_ControlID() + " found.<BR>")); writer.Write(("Its Naming Container is: " + ctrl.get_NamingContainer().get_ID() + "<BR>")); if (ctrl.get_EnableViewState()) { writer.Write("It uses view state to persist its state.<BR>"); } if (ctrl.get_EnableTheming()) { writer.Write("It can be assigned a Theme ID.<BR>"); } if (ctrl.get_Visible()) { writer.Write("It is visible on the page.<BR>"); } else { writer.Write("It is not visible on the page.<BR>"); } writer.Write("</Font>"); } } //Render } //DebugInfoControl
DebugInfoControl を AccessDataSource コントロールと共に Web フォームで使用して、AccessDataSource コントロールに関する情報を表示する方法のコード例を次に示します。
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" assembly="Samples.AspNet.VB" %> <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML> <BODY> <FORM runat="server"> <asp:accessdatasource id="AccessDataSource1" runat="server" datasourcemode="DataReader" datafile="Northwind.mdb" selectcommand="SELECT OrderID FROM Orders WHERE EmployeeID=2"> </asp:accessdatasource> <p> <aspSample:debuginfocontrol id="DebugInfoControl1" runat="server" controlid="AccessDataSource1" /> </FORM> </BODY> </HTML>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" assembly="Samples.AspNet.CS" %> <%@Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML> <BODY> <FORM runat="server"> <asp:accessdatasource id="AccessDataSource1" runat="server" datasourcemode="DataReader" datafile="Northwind.mdb" selectcommand="SELECT OrderID FROM Orders WHERE EmployeeID=2"> </asp:accessdatasource> <p> <aspSample:debuginfocontrol id="DebugInfoControl1" runat="server" controlid="AccessDataSource1" /> </FORM> </BODY> </HTML>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL" assembly="Samples.AspNet.JSL" %> <%@Page Language="VJ#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML> <BODY> <FORM runat="server"> <asp:accessdatasource id="AccessDataSource1" runat="server" datasourcemode="DataReader" datafile="Northwind.mdb" SelectCommand = "SELECT OrderID FROM Orders WHERE EmployeeID=2"> </asp:accessdatasource> <p> <aspSample:debuginfocontrol id="DebugInfoControl1" runat="server" controlid="AccessDataSource1" /> </FORM> </BODY> </HTML>


System.ComponentModel.TypeConverter
System.ComponentModel.StringConverter
System.Web.UI.WebControls.ControlIDConverter
System.Web.UI.WebControls.AssociatedControlConverter
System.Web.UI.WebControls.ValidatedControlConverter


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からControlIDConverter クラスを検索する場合は、下記のリンクをクリックしてください。

- ControlIDConverter クラスのページへのリンク