This documentation is archived and is not being maintained.

ControlCollection.Contains Method

Determines whether the specified server control is in the parent server control's ControlCollection object.

[Visual Basic]
Public Overridable Function Contains( _
   ByVal c As Control _
) As Boolean
[C#]
public virtual bool Contains(
 Control c
);
[C++]
public: virtual bool Contains(
 Control* c
);
[JScript]
public function Contains(
   c : Control
) : Boolean;

Parameters

c
The server control to search for in the collection.

Return Value

true if the specified server control exists in the collection; otherwise, false.

Example

[Visual Basic, C#] The following example uses the System.Web.UI.Contains method to determine whether a Radio3 server control exists in the ControlCollection object for a myForm control, and, if it is, removes it.

[Visual Basic] 
' Create an event handler that uses the 
' ControlCollection.Contains method to verify
' the existence of a Radio3 server control in
' the ControlCollection of the myForm server control.
' When a user clicks the button associated
' with this event handler, Radio3 is removed
' from the collection.
    Sub RemoveBtn_Click(sender As [Object], e As EventArgs)
 If myForm.Controls.Contains(Radio3) Then
      myForm.Controls.Remove(Radio3)
 End If
    End Sub 'RemoveBtn_Click

[C#] 
// Create an event handler that uses the 
// ControlCollection.Contains method to verify
// the existence of a Radio3 server control in
// the ControlCollection of the myForm server control.
// When a user clicks the button associated
// with this event handler, Radio3 is removed
// from the collection.
void RemoveBtn_Click(Object sender, EventArgs e){
    if (myForm.Controls.Contains(Radio3))
    { 
       myForm.Controls.Remove(Radio3);
    }
}

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# 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 | Controls

Show: