ControlCollection.Contains(Control) 方法

定义

确定指定的服务器控件是否在父服务器控件的 ControlCollection 对象中。

public:
 virtual bool Contains(System::Web::UI::Control ^ c);
public virtual bool Contains (System.Web.UI.Control c);
abstract member Contains : System.Web.UI.Control -> bool
override this.Contains : System.Web.UI.Control -> bool
Public Overridable Function Contains (c As Control) As Boolean

参数

c
Control

要在集合中搜索的服务器控件。

返回

如果集合中存在指定的服务器控件,则为 true;否则为 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.
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

适用于

另请参阅