Skip to content

clsNestedMaster

clsNestedMaster is a stateless, Shared-only helper class for navigating ASP.NET's nested master-page hierarchy: it counts how many master-page levels exist above a given page, finds the master at a specific ancestor level (or the root), and locates a named control anywhere in the master tree, searching across ContentPlaceHolder boundaries when needed.

Purpose

  • Determine how many levels of nested master pages exist above a given page (MasterLevelCount).
  • Locate the outermost/root master page in a nested hierarchy (Root, FindMaster).
  • Find a named control anywhere within the nested master-page tree, optionally scoped to a specific ContentPlaceHolder (FindControl).

Context

  • Namespace: SAIF.Presentation.Web.Core
  • Assembly/package: SAIF.Presentation.Web.Core.Infragistics103 (merged into SAIF.BOF.Presentation.Web.Infragistics103 NuGet package)

Public members

Member Signature Purpose
MasterLevelCount Shared ReadOnly Property MasterLevelCount(page As Page) As Integer Returns the number of nested master-page levels found above the given page, by recursively walking Master.Master references.
Root Shared ReadOnly Property Root(page As Page) As MasterPage Returns the outermost (root) master page for the given page.
FindMaster Shared Function FindMaster(page As Page, Optional desiredAncestorLevel As Integer = 1) As MasterPage Returns the master page at the specified ancestor level, counted from the outermost master inward.
FindControl Shared Function FindControl(page As Page, controlID As String, Optional contentPlaceHolderID As String = "") As Control Locates a control by ID anywhere in the master-page tree, optionally scoping the search to a specific ContentPlaceHolder; falls back to a direct FindControl on the root master if the recursive search does not find it.

Behavioral notes

  • MasterLevelCount and FindMaster both recurse from the page's immediate master outward/inward using mutually-recursive private helpers (RecurseMasterLevelCount, RecurseFindMaster).
  • FindControl's recursive search (RecurseFindControl) matches on ContentPlaceHolder.ID when a contentPlaceHolderID is supplied, and otherwise performs a general depth-first traversal of all controls in the tree.

Constraints and usage notes

  • All members are Shared; this class holds no instance state and is used purely as a static utility.
  • Passing an unmatched contentPlaceHolderID may fall through to searching the entire tree rather than a specific placeholder, depending on where the matching ContentPlaceHolder control is found in traversal order*.

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • SAIF.Presentation.Web.Core.Infragistics103\clsNestedMaster.vb