I have some prerender code that is being used to get information from another list to add into the display of the main list.
I am puzzled - the prerender code executes twice.
(function () {
var ctx = {};
ctx.Templates = {};
ctx.OnPreRender = preRenderHandler;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();
function preRenderHandler(renderCtx) {
// Execute SP Services to get external variables to add into current site
};
the code works fine, just executes twice.
I suspect that this site explains why:
namely, that there is an OnLoad and Postback event happening resulting in the preRenderhandler running twice?
Is this correct?
What is the best way to stop the code running twice? Is there any benefit in it running twice?
Thanks!
ctx.OnPreRender
is not related to the blogpost you mention. Where do you reference your JavaScript - maybe it's referenced twice.