Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ControlCollection.Remove Method

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

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

public virtual void Remove (
	Control value
)
public void Remove (
	Control value
)
public function Remove (
	value : Control
)
Not applicable.

Parameters

value

The server control to be removed.

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

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

// 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." ;

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft