2

I created a custom Ribbon button to generate a report in excel for my external lists. When I click on the ribbon button, A modal pop up is displayed. I want to auto close the modal popup after my report has been generated in excel.

This is what I am doing in order to achieve it,

 <CommandUIHandler Command="ExportToExcel" CommandAction="javascript:

   function CloseCallback()
          {  
            SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Cancel);

          }

       var ctx = GetCurrentCtx();
          var listName =ctx.ListTitle;

           var url = $(location).attr('href');

           var currentView =  $('[id*=\'ListTitleViewSelectorMenu\'] span:first').text();  

            var options = {url: L_Menu_BaseUrl +            '/_layouts/CustomRibbon/ExportExternalList.aspx?list=' + listName + '&amp;view=' + currentView + '&amp;url=' + url,
              title: 'Generating Excel!',
              allowMaximize: false,
              showClose: true,
              width: 300,
              height: 100
               };

           SP.UI.ModalDialog.showModalDialog(options);

          setTimeout(function() { CloseCallback(); }, 10000);               
             "/> 
 </CommandUIHandlers>

My Issue is: The modal popup opens for like 10 seconds and then disappears. My report in excel is not generated. Not sure what I am missing here.

Any help would be much appreciated.

2 Answers 2

3

Finally got it working,

Thanks to Karthik's awesome blog about this issue.

http://karthikshare.blogspot.com/2012/03/auto-closing-sharepoint-pop-up-window.html

0

Remove your setTimeout function, and instead close the modal from your actual modal when your report is done.

It can be done by script, as you have code for above already, or by writing that closing script out from the code behind file, like you can see an example of here: http://acveer.wordpress.com/2011/01/25/using-the-sharepoint-2010-modal-dialog/

1
  • Thanks Robert for your suggestions. As suggested, I took the setTimout fucntion and added the setInterval function.After generating the Report, it was not possible to execute any JavaScript from server code to close the pop-up window. So I set the cookie ,deleted the cookie, stoped the timer and closed the pop-up. Thanks.
    – user16023
    Commented Nov 8, 2013 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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