ControlCollection.Remove(Control) メソッド

定義

指定したサーバー コントロールを親サーバー コントロールの ControlCollection オブジェクトから削除します。

public:
 virtual void Remove(System::Web::UI::Control ^ value);
public virtual void Remove(System.Web.UI.Control value);
abstract member Remove : System.Web.UI.Control -> unit
override this.Remove : System.Web.UI.Control -> unit
Public Overridable Sub Remove (value As Control)

パラメーター

value
Control

削除するサーバー コントロール。

次のコード例では、 Remove メソッドを使用して、 myButton サーバー コントロールから子コントロールを削除します。 最初に、コードは Contains メソッドを使用して、 myChildControlControlCollection オブジェクトに含まれているかどうかを判断し、含まれている場合は削除します。

// Use the Contains method to check whether
// a child control exists, and if it does,
// use the Remove method to delete it.        
if (myButton.Controls.Contains(myChildControl))
{
   myButton.Controls.Remove(myChildControl);
   msgRemove.Text = "You removed myLiteralControl.";
}
else msgRemove.Text="The control to remove does not exist." ;
' Use the Contains method to check whether
' a child control exists, and if it does,
' use the Remove method to delete it.        
If myButton.Controls.Contains(myChildControl)
   myButton.Controls.Remove(myChildControl)
   msgRemove.Text = "You removed myLiteralControl."
Else
   msgRemove.Text="The control to remove does not exist." 
End If

注釈

インデックスの場所からコントロールを削除するには、 RemoveAt メソッドを使用します。

適用対象

こちらもご覧ください