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¶
- On construction, read
Session("focuscontrol"); initialize it to an empty string when absent. - When a control is assigned to
BoundControlId, classify it by type name/full name (BR-MVC-027): SAIFMENUmaps to the literal client IDCVTextBox.Infragistics.WebUI.WebCombo.WebCombo,Infragistics.WebUI.WebDataInput.*,Infragistics.WebUI.WebSchedule.WebDateChooser(with a v4.3 variant),SAIF.UIControls.SAIFWebMaskEdit, andSAIFWebDateTimeEditmap to their client IDs paired with the matching editor family.- Any other control type uses the plain client ID.
- The resolved choice is stored in session.
- At
PreRender, if a bound control ID exists, emit aMyFunction()script that calls the family-appropriate focus API —igdrp_getComboById,igcmbo_getComboById,igedit_getById, plaindocument.getElementById, or the_input-suffixed variant for the v4.3 date chooser — optionally calling.select()whenSelectTextis set, wrapped intry{}catch(e){}(BR-MVC-027, BR-MVC-028). - If no bound control ID exists: no focus script is emitted.
- Attach the function to window load using
addEventListenerwhen available, falling back toattachEvent, and register it as theFocusManagerstartup 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.getElementByIdfocus call rather than being skipped.
Related documentation¶
Sources¶
- SAIF.Presentation.Web.MVC/ViewPageBase.aspx.vb