Skip to content

Latest commit

 

History

History
34 lines (17 loc) · 1.44 KB

Retrieving_Control_Instances_by_Their_ID_8b32551.md

File metadata and controls

34 lines (17 loc) · 1.44 KB
loio
8b325518a2ae48ee91eb2dacda1d1420

Retrieving Control Instances by Their ID

A control instance can be found in a fragment by means of its ID.


Due to the above prefixing that guarantees unique IDs, there are different cases possible which require different calls.

Assuming the control has the ID myControl, there are two ways how to retrieve it by its ID.

  • Retrieving a control instance when the fragment is not part of a view

    • When no fragment ID was given: myControl = Element.getElementbyId("myControl"), with Element required from module sap/ui/core/Element

    • When a fragment ID myFrag was given: myControl = Fragment.byId("myFrag", "myControl"), with Fragment required from module sap/ui/core/Fragment

  • Retrieving a control instance when the fragment is embedded into a view and the code is inside a controller. The controller is called this in the following examples.

    • When no fragment ID was given: myControl = this.byId("myControl")

    • When a fragment ID myFrag was given: myControl = this.byId(Fragment.createId("myFrag", "myControl")), with Fragment required from module sap/ui/core/Fragment