Showing posts with label Dialogs. Show all posts
Showing posts with label Dialogs. Show all posts

Friday 31 December 2010

Closing a popup dialog after running server side code

Problem: A base page allows a user to perform additional logic such as inserting a a new row into a list via the Dialog Framework.  The new row is a custom page that is shown thru the Dialog framework.  The custom page contains a web part that allows the user to fill in a form, perform custom logic and insert the record.  You now need the dialog page/popup to close automatically after the server side code is run.  The problem is you need to run the server side code before closing the window.

Initial Hypothesis:  I have been using jQuery with a hidden server control to set a value on the server side after my custom server side actions.  Then after the page reloads due to the postback, on the jQuery $document ready I check if the hidden value has been set and if it has I use the dialog framework to close the page.  A fair amount of work and round trips to solve my problem.

I saw a post on the msdn forums which is much simpler & better solution.  I implemented this and it is much easier and better than my hidden variable approach.

Resolution:
Place the code snippet in the server side code i.e. in the button click after you have performed your server side logic.

More Info:
http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/ba06d5e5-8c4c-4bca-95f8-65f40c1b11fa

Monday 12 July 2010

Sharepoint 2010 Dialogs Framework

Problem: Use the dialog framework to edit information on a SharePoint composite page.
Hypothesis: Dialog framework can open existing pages and pass back values to the calling page. The pass back value can be more than just a simple parameter such as a string. You can return fairly complex flat objects. The example below, displays multiple addresses, allows the user to edit any of them via a modal dialog. and returns the updated address along with the id of the element address to change. To use the dialog framework modals you need SP context so use any of the client OM's or the server OM (i.e. you can't use html unless to load the SP context)
In the parent page inside javascript add the following 2 functions
function OpenDialogAdr(myurl) {
var options = SP.UI.$create_DialogOptions();
options.url = myurl;
options.width = 200;
options.height = 100;
options.dialogReturnValueCallback = CloseCallback;
var dialogSP = SP.UI.ModalDialog.showModalDialog(options);
}
var messageId;
function CloseCallback(dialogResult, returnValue) {
if (dialogResult === SP.UI.DialogResult.OK) {
var adr = returnValue.adr;
var id = returnValue.id
$("#adr-sales-" + id).html(adr);
}
}


Add a link with the appropriate js:
Add the child page, that will return the new address and the id of the item to change.

function onUpdate() {
var adrs = document.getElementById('txtAdr').value;
var ids = document.getElementById('txtId').value;
var mydata = {
adr: adrs,
id: ids
};
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, mydata);
}
function onCancel() {
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult
}

Resolution:
The dialog framework is good for displaying additional information. It is similar in nature to using jQuery & the lightbox plug in.

Resources:
Working with SP2010 modal dialogs