System.Web.UI Namespace Control Class
Determines if the current control contains any child controls.
[ Visual Basic ]
Overridable Public Function HasControls ( ) As Boolean
[ C# ]
public virtual bool HasControls ( );
[ C++ ]
public: virtual bool HasControls ( );
[ JScript ]
public function HasControls ( ) : Boolean;
This property accepts or returns only a boolean value: true if the control contains other controls; otherwise false.
Since this method simply determines if any child controls exist, it can enhance performance by avoiding an unnecessary Controls.Count property call. Count requires a ControlCollection object to be instantiated, and if no children exists, only wastes server resources.
The following example uses the HasControls method to first determine if any controls exist before using the Control.Count property to iterate through a ControlCollection object.
if ( HasControls ( ) ) {
for ( int i=0; i < Controls.Count; i++ ) {
controls [ i ].RenderControl ( writer );
}
}
If HasControls ( ) Then
Dim i As Integer
For i = 0 To Controls.Count - 1
Controls ( i ).RenderControl ( writer )
Next i
End If
if ( HasControls ( ) ) {
for ( var i : int = 0; i < Controls.Count; i++ ) {
Controls [ i ].RenderControl ( writer );
}
} |
|
C# |
VB |
JScript |
Control Members