I have created a Small CheckBox Button within Experience editor in the View tab called "ABC" checking/unchecking that injects/removes html around renderings on the page. Till now everything works fine. Now i have issue where If i go to View tab and Check "ABC" it adds sample HTML around controls than i navigate to "Home" Tab and refresh the page and My java script is not called that resides within View tab on page refresh. Although after page refresh as i click on View tab my script gets executed as I am storing the state in registry and HTML gets injected but not on page load although stored state is still there.

Can some one throw a light what can be a issue here?

Here is my sample script.

define(["sitecore", "/-/speak/v1/ExperienceEditor/ExperienceEditor.js"], function (Sitecore, ExperienceEditor) {
Sitecore.Commands.AddHtmlToControls =
    commandContext: null,
    isEnabled: true,

    canExecute: function (context) {
        if (!ExperienceEditor.isInMode("edit")
          || !context
          || !context.button
          || context.currentContext.isFallback) {
            return false;

        toggleRenderingHtml(context.button.get("isChecked") == "1")
        if (!Sitecore.Commands.AddHtmlToControls.commandContext) {
            this.commandContext = ExperienceEditor.getContext().instance.clone(context);

        return true;

    execute: function (context) {
        ExperienceEditor.PipelinesUtil.generateRequestProcessor("ExperienceEditor.ToggleRegistryKey.Toggle", function (response) {
            response.context.button.set("isChecked", response.responseValue.value ? "1" : "0");

            toggleRenderingHtml(response.context.button.get("isChecked") == "1");

        }, { value: context.button.get("registryKey") }).execute(context);

var toggleRenderingHtml = function (enabled) {

    if (enabled) {
       //some code logic here 
    } else {

       //some code logic here 

The reason why on Page Load it does not trigger the JavaScript is because you need to set the PostponedCall value to false

Using Sitecore Rocks, on the rendering SmallCheckButton, view the Properties window and scroll down up to the Event Section. Then, in the field PostponedCall, set the value to false. A screenshot is provided below:

enter image description here

Your JavaScript methods will then get triggered even if you have click the Home Tab and the refreshes the page.

  • Thanks Hishaam for the help and this does sounds like an answer but for me somehow when this changes are deployed does not work and my JS it still not called on page load except when i click on View tab. I'll keep you posted. – Jaydeep May 16 '17 at 6:09
  • This did resolve the issue, till now problem was with our deployment. Many thanks Hishaam. – Jaydeep May 22 '17 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.