As we mentioned in a previous post, SharePoint 2010 uses a client dialog framework for elegantly showing forms in a dialog box without having to leave the current page.  In this same post, we also mentioned the IsDlg URL parameter, and how it can be added to nearly any page to prepare it for showing in a dialog (essentially a 'quick-n-dirty' way of removing the navigation, quick launch, etc.). 

Armed with this knowledge, we assumed that we could use the IsDlg feature for a recent project, which required a specific page on SharePoint to be shown without any 'standard' UI components (navigation, title bars, ribbon, quick launch, etc.).  After constructing the page, we navigated to the URL adding the IsDlg=1 parameter and everything looked perfect; a quick win (so we thought).  However, what I have not yet told you is that the page we were viewing was a 'new form' for a list, which requires submitting the page to save the data back to the SharePoint list.  As we tested the form and submitted the data, we were immediately presented with a JavaScript error.  After a short bit of investigation, we realized that the IsDlg parameter is nice, but certainly not fool-proof.

Here's what happened:
By adding the IsDlg=1 parameter to your URL, you essentially tell SharePoint that this page is being displayed in a the client dialog framework (i.e. a dialog box).  At this point, it has to make some assumptions, and one of these is that you are actually doing what you say you are (go figure!).  In our case, we were not actually using the dialog box, but were instead showing the page directly in the browser and using the parameter to simply remove the UI elements from our page.  Behind the scenes, with the assumption that you are in fact in a dialog box, SharePoint tries to close the page and/or navigate to another page upon submission of the form being shown in the dialog box.  When the page is shown without the dialog, certain client objects do not exist, which essentially leads to 'object not found' errors when the JavaScript code executes to close/navigate from the dialog box.

** I should note that this does not affect display forms or static pages which do not submit a form. **

Our Solution:
Many of you may remember the plethora of CSS tricks used within Content Editor Web Parts (CEWP) in SharePoint 2007, and sure enough there are similar tricks for SharePoint 2010.  By simply identifying the IDs and/or CSS classes being used by certain UI elements, we are able to elegantly hide these from the page, essentially simulating the IsDlg parameter.

The CSS:

   1: <style type="text/css">
   3: /* Top Nav */
   4: #s4-titlerow {
   5:     DISPLAY: none
   6: }
   8: /* Ribbon */
   9: #s4-ribbonrow {
  10:     DISPLAY: none
  11: }
  13: /* Quick Launch */
  14: #s4-leftpanel {
  15:     DISPLAY: none
  16: }
  17: .s4-ca {
  18:     MARGIN-LEFT: 0px
  19: }
  20: </style>

The CSS above can be placed into a CEWP to hide the Top Navigation, Ribbon, and Quick Launch UI elements.  In our case, we packaged this into a single DWP file named Simulate_IsDlg.dwp.  We can now reuse this code on any form as needed.

NOTE: Now that the ribbon has been removed from your page, you may find it difficult to place the page into Edit mode to add/edit web parts.  Here are two quick methods for you:
1) Add the toolpaneview=2 or toolpaneview=3 parameter to your URL.  Each opens a different version of the Add Web Parts menu.
2) Add the contents=1 parameter to your URL and close the CEWP web part which hides the ribbon (you can add it back by adding a web part and selecting "Closed Web Parts").
* There are more methods, but none better than one of the above options; we prefer option #1. 

UPDATE 06/30/2011:
3) You can add the DisplayMode=Design parameter, which will place the page in design mode as well.  There are quite a few other flags for this parameter as well, which I'll cover in a future blog post.

BONUS TIP: Parameters can be added to the source URL parameter as well.  For example, after completing a SharePoint survey, you may want the user to be redirected to a thank you page, which is free from UI elements as well.  To do this, we can simply construct the source URL parameter as: source=/pages/thankyou.aspx?IsDlg=1.