Solved

How to close a modalDialog from a webpart page in Sharepoint 2010

Posted on 2011-09-27
8
2,295 Views
Last Modified: 2012-05-12
Hello all,

In sharepoint (2010 foundation) I am trying to use the SP.UI.ModalDialog.showModalDialog function to open a webpart page.
(and it succeeds!!)
However: closing the modalDialog fails. It seems I am closing the webpart page displayed inside de modalDialog but the dialog itself stays open.
The webpart used is a SmartPart, which reads the contents of an aspx file from the server.

This is the code I use to open the dialog:
<script language='text/javascript'>
function UurRegistratieWBS(LineNr, lblAfk, projectNr, BudgetCode) {
            
        var options = SP.UI.$create_DialogOptions();
        options.url = '/ERP/SitePages/UurRegistratie.aspx?wbsnr=' + LineNr + '&user=' + lblAfk + '&project=' + projectNr + '&BudgetCode=' + BudgetCode;
        options.title = "Tijdsregistratie WBS";
        options.showClose = true;
        options.autoSize = true;
        options.dialogReturnValueCallback = Function.createDelegate(null, CloseDialog);

         SP.UI.ModalDialog.showModalDialog(options);
      }
   </script>

Open in new window


...And below is the code I (try to) use in the webpart page :
 
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSluiten.Click

    Me.Response.Write("<script language='text/javascript'>SP.UI.ModalDialog.close(SP.UI.DialogResult.cancel);</script>")
    Me.Parent.Page.Response.Clear()
    Me.Parent.Page.Response.Write("<script language='text/javascript'>SP.UI.ModalDialog.close(SP.UI.DialogResult.cancel);</script>")
  End Sub

Open in new window


As said earlier: the webpart page itself is closed, but the dialogbox stays open and has to be closed manually.
Can someone help me with this?

Thanks,

    Paul
0
Comment
Question by:paeep
  • 5
  • 2
8 Comments
 
LVL 9

Expert Comment

by:dexterrajesh
ID: 36708788
0
 

Author Comment

by:paeep
ID: 36708988
Hey,

I already tried that kind of code (it's all over the internet ;-) )

Could there be a possibility that my modalDialog is opened twice?
--> after I 'close' the dialog, it seems to grow a little in size (as in a default modal popup dialog)

However, I only get 1 result from the callback function.
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36709093
Instead of SP.UI.ModalDialog.close() method try window.close()
0
 

Author Comment

by:paeep
ID: 36709124
That was the initial setup.
Doesn't work either...
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Accepted Solution

by:
paeep earned 0 total points
ID: 36715506
I found the solution myself:

Page.Response.Clear()
Page.Response.Write("<script type='text/javascript'>window.frameElement.commonModalDialogClose(1, 'registratie');</script>")
Page.Response.End()
Page.Response.Flush()

Open in new window


The window.frameElement does the job. Don't know why.
I tried it with IE8 / IE9 / chrome and it all works, whereas the previous 'solutions' did not.

If someone can clarify this, I'd be happy to read it :-)
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36715548
0
 

Author Closing Comment

by:paeep
ID: 36902120
final solution
0
 

Author Comment

by:paeep
ID: 36715924
I found what I needed explicitly through one of your links:
http://blogs.msdn.com/b/sharepointdev/archive/2011/01/13/using-the-dialog-platform.aspx

Methods Inside a Dialog

When you’re inside a dialog, there are alternate methods to operate on the dialog. The APIs are created dynamically to increase performance and keep from loading the entire SP.UI.Dialog.js file since it is loaded in the parent window. The following methods and properties are available using the window.frameElement class.
...

Thanks!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now