This documentation is archived and is not being maintained.

ControlCollection.Remove Method

Removes the specified server control from the parent server control's ControlCollection object.

[Visual Basic]
Public Overridable Sub Remove( _
   ByVal value As Control _
)
[C#]
public virtual void Remove(
 Control value
);
[C++]
public: virtual void Remove(
 Control* value
);
[JScript]
public function Remove(
   value : Control
);

Parameters

value
The server control to be removed.

Remarks

To remove a control from an index location, use the RemoveAt method.

Example

[Visual Basic] The following example uses the Remove method to delete a child control from the myButton server control. First the code uses the System.Web.UI.Contains method to determine whether the myChildControl is contained in the ControlCollection object, and, if it is, removes it.

[Visual Basic] 
' 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

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

ControlCollection Class | ControlCollection Members | System.Web.UI Namespace | RemoveAt | Controls

Show: