---
title: Restore menu state on page pre-load
summary: Re-establish the left menu's session-scoped state (expanded/collapsed, current page, context value) at the start of each page life cycle.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.Controls.V2.Menu
reference_type: package
operation_id: OP-MENU-007
trigger: "`SAIFMenu.Page_PreLoad`, subscribed via the `ViewPageBase.PreLoad` event."
---

# Restore menu state on page pre-load

Re-establish the left menu's session-scoped state (expanded/collapsed, current page, context value) at the start of each page life cycle. This operation is implemented by `SAIFMenu.Page_PreLoad`.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-MENU-007 |
| **Trigger** | `SAIFMenu.Page_PreLoad`, subscribed via the `ViewPageBase.PreLoad` event. |
| **Inputs** | `m_Page.ViewID`; `IsPostBack`; authenticated identity; stored `SHOWAPPS` preference; `Session("CVTextBox" & ViewID)`. |
| **Outputs** | `ShowApps` state; cached `CurrentPage`; restored `ContextValue`. |
| **Primary components** | `SAIFMenu.Page_PreLoad` |
| **Entry point** | `SAIF.Presentation.Web.Controls.V2.Menu/SAIFMenu.vb` |

## Steps

1. Capture `m_Page.ViewID` (or empty string when the page is not a `ViewPageBase`). Enforces [BR-MENU-036](../business-rules.md#br-menu-036-session-keys-are-namespaced-by-the-pages-viewid).
2. On a non-postback with an authenticated identity, read `SHOWAPPS` at `PrefScope.AppLevel` and set `ShowApps` accordingly, defaulting to expanded when the preference is absent. Enforces [BR-MENU-037](../business-rules.md#br-menu-037-the-showapps-preference-is-applied-only-on-the-initial-authenticated-request), [BR-MENU-038](../business-rules.md#br-menu-038-the-applications-list-defaults-to-expanded-when-no-preference-is-stored).
   - Delegates to `clsPreferences` (`SAIF.Presentation`).
3. If the current page is not yet cached in view state, resolve it via `NavigationData.GetCurrentPage()`. Enforces [BR-MENU-039](../business-rules.md#br-menu-039-the-current-page-is-resolved-once-and-cached-in-view-state).
   - Delegates to `NavigationContext`.
4. On a non-postback, restore the context value from `Session("CVTextBox" & ViewID)` when present. Enforces [BR-MENU-040](../business-rules.md#br-menu-040-the-context-value-is-restored-from-session-on-the-initial-request-only).

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start(["SAIFMenu.Page_PreLoad, subscribed via ViewPageBase"]) --> Capture["Capture m_Page.ViewID (empty if not ViewPageBase)"]
	Capture --> PostBack{Non-postback and authenticated?}
	PostBack -->|Yes| ReadPref["Read SHOWAPPS at PrefScope.AppLevel, default expanded"]
	ReadPref --> Restore["Restore context value from Session(&quot;CVTextBox&quot; & ViewID)"]
	PostBack -->|No| Cached{Current page cached in view state?}
	Restore --> Cached
	Cached -->|No| Resolve["NavigationData.GetCurrentPage()"]
	Cached -->|Yes| End(["ShowApps state; cached current page; restored context"])
	Resolve --> End
```

## Failure and edge-case behavior

- No exceptional failure paths beyond those noted in the steps above.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Database tables](../database-tables.md)

## Sources
- `SAIF.Presentation.Web.Controls.V2.Menu/SAIFMenu.vb`
