Refreshing Dynamic HTML Content in SAPUI5: Handling Updates and Rerendering Issues

Problem Statement

In SAPUI5, developers often use the HTML control to embed dynamic or external HTML content within their apps. A common challenge arises when you need to update this content dynamically (e.g., loading new HTML from an API or changing a map view).

Many try rerender() on the HTML control, but:

  • rerender() is deprecated.
  • Using setContent() alone may not trigger a full DOM refresh in some browsers.
  • Event handlers or scripts inside the new HTML may not execute as expected.

The result: the new content either does not render, or old scripts remain bound, leading to broken UI interactions.

Solution

  1. Get your HTML control reference
var oHtml = this.byId("searchHTML");
  1. Hide the control before updating content
oHtml.setVisible(false);
  1. Set the new HTML content
oHtml.setContent('<iframe src="newContent.html" width="100%" height="600"></iframe>');
  1. Make the control visible again
oHtml.setVisible(true);

Why it works:

  • Hiding the control forces UI5 to completely redraw the control when it becomes visible again.
  • The new HTML is fully injected into the DOM.
  • Event handlers and scripts inside the new HTML now execute as expected.

Key Takeaways

  • Deprecated methods like rerender() should be avoided in modern SAPUI5.
  • Visibility toggling around setContent() is a safe and effective alternative.
  • This approach ensures that dynamic HTML content updates reliably, including scripts, iframes, and event listeners.