asp.net.ph

Control.HasControls Method

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;

Return Value

This property accepts or returns only a boolean value: true if the control contains other controls; otherwise false.

Remarks

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.

Example

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 );
   }
}
  C# VB JScript

See Also

Control Members Skip Navigation Links




Previous page Back to top Next page

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note