次の方法で共有


ControlCollection.Contains メソッド

指定したサーバー コントロールが親サーバー コントロールの ControlCollection オブジェクト内にあるかどうかを確認します。

Public Overridable Function Contains( _
   ByVal c As Control _) As Boolean
[C#]
public virtual bool Contains(Controlc);
[C++]
public: virtual bool Contains(Control* c);
[JScript]
public function Contains(
   c : Control) : Boolean;

パラメータ

  • c
    コレクション内で検索されるサーバー コントロール。

戻り値

指定されたサーバー コントロールがコレクションにある場合は true 。それ以外の場合は false

使用例

[Visual Basic, C#] System.Web.UI.Contains メソッドを使用して、 myForm コントロールの ControlCollection オブジェクト内に Radio3 サーバー コントロールが存在するかどうかを確認し、存在する場合はそれを削除するコード例を次に示します。

 
' Create an event handler that uses the 
' ControlCollection.Contains method to verify
' the existence of a Radio3 server control in
' the ControlCollection of the myForm server control.
' When a user clicks the button associated
' with this event handler, Radio3 is removed
' from the collection.
    Sub RemoveBtn_Click(sender As [Object], e As EventArgs)
 If myForm.Controls.Contains(Radio3) Then
      myForm.Controls.Remove(Radio3)
 End If
    End Sub 'RemoveBtn_Click

[C#] 
// Create an event handler that uses the 
// ControlCollection.Contains method to verify
// the existence of a Radio3 server control in
// the ControlCollection of the myForm server control.
// When a user clicks the button associated
// with this event handler, Radio3 is removed
// from the collection.
void RemoveBtn_Click(Object sender, EventArgs e){
    if (myForm.Controls.Contains(Radio3))
    { 
       myForm.Controls.Remove(Radio3);
    }
}

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

必要条件

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

参照

ControlCollection クラス | ControlCollection メンバ | System.Web.UI 名前空間 | Controls