Interface ICanHide
public interface ICanHide
Properties
IsHidden
Gets or sets a value indicating whether the control is hidden from view
bool IsHidden { get; set; }
Property Value
- bool
trueif the control is hidden; otherwise,false. Default isfalse.
Remarks
This property provides reliable visibility control that persists across postbacks using ViewState and is not affected by parent control hierarchy cascading behavior. In a scenario where you need to set the visibility of a child control independent of the visibility of its parent control, you can use this instead of the default Visible property. (For example, this may be useful for implementing visibility rules based on business logic.)
Rationale: When a parent control is hidden by setting Visible = false, all child controls automatically return false for their Visible property getter, regardless of their individual visibility settings. This makes it impossible to reliably determine a child control's intended visibility state when applying business rules "bottom-up" (i.e., making a control visible only if it contains visible child controls).
Example: If you set ChildControl.Visible = true but ParentControl.Visible = false, then ChildControl.Visible getter will return false, losing the original intended state of the child control.
Solution: In a scenario that requires a "bottom-up" implementation for visibility, use a separate property (IsHidden) instead, which maintains independent state for each control without hierarchy interference.