Saturday, October 8, 2011

In SharePoint 2010, the new feature is added is the dialog framework. With the help of this, user stays on the same page and able to get the information without go away from the current page. So, there are ways that we can close the dialog from the code in different ways. Below are the mainly used implementations in javascript and code behind.
<script type='text/javascript'>window.frameElement.commitPopup()</script>

The window.frameElement is the node which holds the current dialog window. commitPopup() method which commits the popup and closes the dialog from the page window. So, by simply calling the above method, the dialog window will close automatically.

HttpContext context = HttpContext.Current;
if (HttpContext.Current.Request.QueryString["IsDlg"] != null){
context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");

The dialog framework recognizes an additional parameter in the request named "IsDlg=1", which says open the page in dialog box. So, in code-behind simply check for query string parameter and if it exists then call the javascript method mentioned above by writing it to browser. So, when it executed the dialog will be closed.

This is a very nice tip which helps in some custom implementations. Hope it helps.
Categories: ,


  1. Nice tip - thanks

  2. Thanks for the tips, I tell you the problem I have with some SharePoint lists. The ribbon disappears when entering text making it impossible to save the item. Then I go to advanced settings and turn off the dialog so I can just display the post in a full window. However even when that is set to no the dialog still appears. What can i do?