Javascript:
<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.
Code-Behind:
HttpContext context = HttpContext.Current;
if (HttpContext.Current.Request.QueryString["IsDlg"] != null){
context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
context.Response.Flush();
context.Response.End();
}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.