Showing posts with label Dialog. Show all posts
Showing posts with label Dialog. Show all posts

Saturday, October 8, 2011

Close SharePoint 2010 Dialog through code

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.
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.

Tuesday, August 11, 2009

JQuery dialog open only first time problem, solution

This is a big problem to me for long time in JQuery. I downloaded the Jquery UI min file and started using in my projects. On the way, there are some requirements where I need to show the dialog box and execute some logic. But, whenever I click some button to open a dialog, very first time only it opens like a charm. From the time when I close it, it will never open again by clicking on open dialog link. This gave me lot of frustration and I don’t know where the exact problem is. After reading all the documentation in JQuery docs, finally found the problem and fixed it in seconds.

Solution:

$("#dialog").dialog({ modal: true, resizable: false,
draggable: false, width: 515, height: 245 });

$("#dialog").dialog('open');

I know everyone is declaring only the first statement in their code and no one will write the second statement to open the dialog. Below is the explanation for it.

As far as I understood, what JQuery framework doing internally is, When we write the first statement, it is treating it as the initiation of the dialog for the div or HTML control. Because of adding "model:true", it will open for the first time, when you click on a link and never open again once you closed. Because no where we mentioned to open the dialog in the first statement.

And about second statement, JQuery is calling the dialog property and forcibly loading the dialog to the DOM and shows it on the screen. So, open property/attribute will do the trick. So, whenever you want to use a dialog box in JQuery, this is the code you need to use to open it as many times as you want.

Is this what you are looking for? Or do you know any other ways to implement it? Please post all your ideas here.