Close the SharePoint 2010 Modal Dialog from the code-behind

SharePoint 2010 introduces the new Modal dialog framework, which opens up a light-box type pop-up in the page. Chakradeep Chandran (an former sharepoint server MVP) wrote an excellent article/tutorial explaining how to use the sharepoint modal Dialog framework.

In addition to the Chak’s article, If you are trying to close the SharePoint Modal Dialog from the code-behind, the below code would help

HttpContext context = HttpContext.Current;
if (HttpContext.Current.Request.QueryString["IsDlg"] != null)
context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup()</script>");
Posted in Sharepoint 2010
6 comments on “Close the SharePoint 2010 Modal Dialog from the code-behind
  1. Colin Blake says:

    Where would we put this code? in a CEWP?


    • acveer says:

      In the code behind of the custom application page. When we open up the SP 2010 Modal Dialog, we usually open an aspx page. For example

      function portal_openModalDialog() {
      var options = SP.UI.$create_DialogOptions();
      options.width = 500;
      options.height = 250;
      options.url = "/_layouts/StandardsPortal/ChangePassword.aspx";
      options.dialogReturnValueCallback = Function.createDelegate(
      null, portal_modalDialogClosedCallback);

      Once the Dialog opens, at some point in code you would want the dialog to be closed automatically from code behind. We can use this code in the code behind to do this.


  2. Rohit says:

    Thanks Man you save my day…………..


  3. Prasun Sarkar says:

    Its really a helpful info….. thanx a lot


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: