ControlIDConverter クラスとは? わかりやすく解説

ControlIDConverter クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

現在のコンテナからコントロール IDリスト取得するコンバータ提供します

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

Public Class ControlIDConverter
    Inherits StringConverter
Dim instance As ControlIDConverter
public class ControlIDConverter : StringConverter
public ref class ControlIDConverter : public
 StringConverter
public class ControlIDConverter extends StringConverter
public class ControlIDConverter extends
 StringConverter
解説解説
使用例使用例

コントロール ID表示を TypeConverter に対して要求するクラス内で ControlIDConverter使用する方法コード例次に示しますDebugInfoControl は、現在の Web フォーム格納されているコントロール一部情報印刷する単純なコントロールです。その ControlID プロパティは、ControlIDConverter をそのプロパティ使用する TypeConverter として指定する TypeConverterAttribute で装飾されています。DebugInfoControlRender メソッドオーバーライドして、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>
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.ComponentModel.TypeConverter
     System.ComponentModel.StringConverter
      System.Web.UI.WebControls.ControlIDConverter
         System.Web.UI.WebControls.AssociatedControlConverter
         System.Web.UI.WebControls.ValidatedControlConverter
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ControlIDConverter メンバ
System.Web.UI.WebControls 名前空間
TypeConverter
AssociatedControlConverter クラス
ValidatedControlConverter
その他の技術情報
方法 : 型コンバータ実装する
一般的な型変換


このページでは「.NET Framework クラス ライブラリ リファレンス」からControlIDConverter クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からControlIDConverter クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からControlIDConverter クラス を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ControlIDConverter クラス」の関連用語

ControlIDConverter クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ControlIDConverter クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS