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 方法确定 对象中ControlCollection是否myChildControl包含 ,如果包含,则将其删除。

// 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 方法。

适用于

另请参阅