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's the relevant 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);

    function ConfirmationCallback(dialogResult, returnValue) {
        if (dialogResult == SP.UI.DialogResult.OK) {
            // do whatever needed

    OpenInDialog('test', 'http://portal.dev.loc/sites/TestSite/_layouts/Test.aspx');


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. Any clue what I'm doing wrong?

  • Can you check the errors again as I'm guessing that the real error is further up the chain. The one posted has no relation to this code whatsoever. – Dave Wise Aug 29 '12 at 16:40
  • Same thing I was thinking. What other js is on the page? – RJ Cuthbertson Aug 29 '12 at 16:41
  • Sorry for the late response. There is no other javascript on the page. I'm trying to just load a page, and load a simple modal in it. The exception is in a function that is checking for valid parameters. I'll try to post again tomorrow with more information. I think that it might be that I'm missing a library somewhere. But this is a SharePoint aspx page with a Master page and everything. Shouldn't it already have the correct libraries? I had noticed that an attempt to get SPContext.Current on the page failed. So something might be wrong, and the page isn't linked to SP properly. – Craig Aug 29 '12 at 21:34
  • Also worth pointing out, I don't have any calendar code anywhere. I don't know why I'm getting an error about a Calendar Selector when there are no calendar selectors anywhere. – Craig Aug 30 '12 at 12:20

Make sure that sp.ui.dialog.js has completed loading before you call your opendialog function. Call the OpenInDialog() function like this:


OpenInDialog('test', 'http://portal.dev.loc/sites/TestSite/_layouts/Test.aspx');

|improve this answer|||||
  • Nope. Exact same error. – Craig Aug 30 '12 at 12:13
  • I think you had the right idea with your comment. It didn't work, but it got me thinking. I had tried doing $(document).ready, but that didn't work. I just moved the method call to a button and it worked. I had been trying to just start with the simplest possible modal example, but it was too simple. As long as I triggered the modal with a button, instead of immediately on page load, it worked fine. – Craig Aug 30 '12 at 18:43
  • 1
    Hmmm then I think your problem was that some of the js files necessary were not getting loaded before your code was called. Did you try putting in "sp.ui.dialog.js" in place of "sp.js" in my code? (Also remove the scriptlinks as you say they are not necessary since the default sp js files are always loaded implicitly) – Vardhaman Deshpande Aug 30 '12 at 19:09
  • Vardhaman, you got it. That was the correct library that hadn't loaded in time. – Craig Aug 31 '12 at 15:49
  • Change your answer to sp.ui.dialog.js and I'll mark it as correct. Can I mark two things as correct? I feel like you should get credit for pointing me in the right direction. – Craig Aug 31 '12 at 15:51

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.

|improve this answer|||||
  • But I still think that @VarhamanDeshpande is right in his comment that some file hasn't loaded yet. You should be able to open the dialog without a button click anyway. Can you try (just for a test) to open it on $(function() { window.setTimeout(..., 10000); }); so it will open after 10 seconds when page is ready. – Robert Koritnik Aug 31 '12 at 8:34
  • Yup, Varhaman was correct. – Craig Aug 31 '12 at 15:51
  • Actually, to specify, Varhaman was on the right track. But it was sp.ui.dialog.js that hadn't loaded in time, not sp.js. – Craig Aug 31 '12 at 16:24

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.