Table of Contents

Class ControlVisibilityHelper

Namespace
InSite.Common.Web.UI
Assembly
InSite.UI.dll
public class ControlVisibilityHelper
Inheritance
ControlVisibilityHelper
Inherited Members

Remarks

The built-in Control.Visible property cannot be trusted because Microsoft implemented a recursive getter. This means the property value of a parent control overrides the property value of a child control, which is not expected or intuitive, and this breaks any logic that assumes the visibility of a parent control can be decided after the visibility of its child controls has been determined using business rules. (I suspect the developers at Microsoft originally intended for the Visible property to be a read-only on the control hierarchy. Regardless, we consider it unsafe, and it should be avoided.)

This helper class uses Bootstrap's d-none class exclusively to show/hide supported controls. Notice it does NOT get or set Visible (or IsHidden) property values. This is by design, to ensure this helper can be used where it is needed with no side-effects on any existing functionality related to visibility and rendering.

Constructors

ControlVisibilityHelper()

public ControlVisibilityHelper()

Methods

Hide(Control)

Hides a control by adding Bootstrap's d-none class

public void Hide(Control control)

Parameters

control Control

The control to hide

Hide(Control[])

Batch operation to hide multiple controls

public void Hide(Control[] controls)

Parameters

controls Control[]

Array of controls to hide

IsHidden(Control)

Checks if a control is currently hidden via Bootstrap's d-none class

public bool IsHidden(Control control)

Parameters

control Control

The control to check

Returns

bool

True if the control appears to be hidden

SetVisibility(Control, Func<bool>)

Advanced visibility management with conditional rules

public void SetVisibility(Control control, Func<bool> condition)

Parameters

control Control

The control to manage

condition Func<bool>

Function that returns true if control should be visible

Show(Control)

Shows a control by removing Bootstrap's d-none class

public void Show(Control control)

Parameters

control Control

The control to show

Show(Control[])

Batch operation to show multiple controls

public void Show(Control[] controls)

Parameters

controls Control[]

Array of controls to show

Toggle(Control, bool)

Toggles control visibility using Bootstrap's d-none class

public void Toggle(Control control, bool show)

Parameters

control Control

The control to toggle

show bool

True to show, false to hide