Wednesday, March 23, 2011

SharePoint 2010: SP.UI.ModalDialog.showModalDialog not ready

I'm building a custom component which displays "ads". It needs to check a list to see if the current user has seen the ad. If they haven't then display a SharePoint 2010 modal dialog.

What I did (Javascript):
_spBodyOnLoadFunctionNames.push("OpenMyAd");

What was needed:
ExecuteOrDelayUntilScriptLoaded(OpenMyAd, "sp.ui.dialog.js");

Which does exactly what it says on the tin... It waits until the script is loaded and then executes what I told it to.

Credit goes to Sing Chan and his post.