Export (0) Print
Expand All

ControlCollection.Contains Method

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

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

public virtual bool Contains (
	Control c
)
public boolean Contains (
	Control c
)
public function Contains (
	c : Control
) : boolean
Not applicable.

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.

// 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);
    }
}

// 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.get_Controls().Contains(Radio3)) {
        myForm.get_Controls().Remove(Radio3);
    }
} //RemoveBtn_Click

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:
© 2014 Microsoft