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 方法來判斷 是否 myChildControl 包含在 物件中 ControlCollection ,如果是,則會將其移除。

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

適用於

另請參閱