Skip to content

Restore input focus

A client-script convenience that restores keyboard focus to the last control the user was working in, spanning both plain ASP.NET controls and Infragistics editor families that each expose focus differently through JavaScript.

Field Value
Operation ID OP-MVC-12
Trigger PreRender, when a bound control ID is recorded
Inputs Session("focuscontrol"), the bound control's type/full name
Outputs A registered startup script that focuses (and optionally selects) the control on page load
Primary components ViewPageBase.NavigationManager.GenerateScripts
Entry point SAIF.Presentation.Web.MVC/ViewPageBase.aspx.vb

Steps

  1. On construction, read Session("focuscontrol"); initialize it to an empty string when absent.
  2. When a control is assigned to BoundControlId, classify it by type name/full name (BR-MVC-027):
  3. SAIFMENU maps to the literal client ID CVTextBox.
  4. Infragistics.WebUI.WebCombo.WebCombo, Infragistics.WebUI.WebDataInput.*, Infragistics.WebUI.WebSchedule.WebDateChooser (with a v4.3 variant), SAIF.UIControls.SAIFWebMaskEdit, and SAIFWebDateTimeEdit map to their client IDs paired with the matching editor family.
  5. Any other control type uses the plain client ID.
  6. The resolved choice is stored in session.
  7. At PreRender, if a bound control ID exists, emit a MyFunction() script that calls the family-appropriate focus API — igdrp_getComboById, igcmbo_getComboById, igedit_getById, plain document.getElementById, or the _input-suffixed variant for the v4.3 date chooser — optionally calling .select() when SelectText is set, wrapped in try{}catch(e){} (BR-MVC-027, BR-MVC-028).
  8. If no bound control ID exists: no focus script is emitted.
  9. Attach the function to window load using addEventListener when available, falling back to attachEvent, and register it as the FocusManager startup script.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([NavigationManager construction]) --> S1[Read Session focuscontrol]
    S1 --> D1{BoundControlId assigned?}
    D1 -->|No| EndNone([No focus script])
    D1 -->|Yes| S2[Classify control by type/full name]
    S2 --> S3[Store client ID + family in session]
    S3 --> S4[PreRender: emit MyFunction with try/catch]
    S4 --> S5[Attach to window load via addEventListener/attachEvent]
    S5 --> EndOk([FocusManager startup script registered])

Failure and edge-case behavior

  • The generated focus script wraps its call in try{}catch(e){}, so a client-side focus failure (e.g., the control was removed from the DOM) is silently swallowed and never surfaces to the user (BR-MVC-028).
  • A control type not matching any recognized family still gets a best-effort plain document.getElementById focus call rather than being skipped.

Sources

  • SAIF.Presentation.Web.MVC/ViewPageBase.aspx.vb