I’m migrating a project from SP2007 to SP2010. I want to get a modal popup to work, to open up the New Item window of a list from an aspx page. I can’t get the modal to work in the most basic example, and I can’t figure out what’s going on.
I keep getting the following error if I use Developer Tools and enable Script Debugging:
SCRIPT5022: Sys.ArgumentTypeException: Object of type 'SP.UI.ApplicationPages.CalendarSelector' cannot be converted to type 'Sys.IDisposable'.
Here is a code snippet:
<SharePoint:ScriptLink ID="ScriptLink3" Language="javascript" Name="../ProjectFolder/jquery/jquery-1.7.2.min.js" Defer="false" runat="server" />
<SharePoint:ScriptLink ID="ScriptLink1" Language="javascript" Name="../ProjectFolder/jquery/jquery-ui-1.8.12.custom.min.js" Defer="false" runat="server" />
<SharePoint:ScriptLink ID="ScriptLink4" Language="javascript" Name="../MicrosoftAjax.js" Defer="false" runat="server" />
<SharePoint:ScriptLink ID="ScriptLink5" Language="javascript" Name="../SP.debug.js" Defer="false" runat="server" />
<SharePoint:ScriptLink ID="ScriptLink6" Language="javascript" Name="../SP.UI.Dialog.js" Defer="false" runat="server" />
<script type="text/javascript">
function OpenInDialog(title, url) {
var options = SP.UI.$create_DialogOptions();
options.title = title;
options.width = 680;
options.height = 500;
options.url = url;
options.dialogReturnValueCallback = Function.createDelegate(null, ConfirmationCallback);
SP.UI.ModalDialog.showModalDialog(options);
}
function ConfirmationCallback(dialogResult, returnValue) {
if (dialogResult == SP.UI.DialogResult.OK) {
}
}
OpenInDialog('test', 'http://portal.dev.loc/sites/TestSite/_layouts/Test.aspx');
</script>
I keep thinking that the problem is related to SP.UI.Dialog.js, but my reference is correct, and I can’t figure out why it isn’t working. This is driving me nuts. Any clue what I’m doing wrong?
The problem was a race condition that wasn’t solved by putting the method call in $(document).ready, which I had tried before (not sure why I didn’t have it in this example).
I was trying to just do a simple modal, but made it too simple. Trying to open a modal immediately when the page was opened didn’t work. Moving the exact same method call to a button worked fine. None of the Scriptlinks were necessary. All the jquery libraries were already provided on the page by SharePoint.
I knew it would be something stupid. Thanks Vardhaman, for leading me in the right direction.
Also, Vardhaman’s answer here worked:
https://sharepoint.stackexchange.com/questions/44548/cant-get-a-basic-modal-to-work-on-2010/44687#comment41263_44687
ExecuteOrDelayUntilScriptLoaded(function(){
},”sp.ui.dialog.js”);