When calling a modal dialog in SharePoint 2010 you can pass parameter data to it as shown below;
var dialogArgs = { WftForm: formName, WftId: workflowTypeId, WftColor: formColor }; var dialogOptions = { url: "my-dialog.aspx", title: "Dialog Title", showClose: true, allowMaximize: false, autoSize: true, args: dialogArgs, dialogReturnValueCallback: onDialogClosed }; SP.UI.ModalDialog.showModalDialog(dialogOptions);
And in your dialog code you can retrieve the parameter data using the following;
var dialog = SP.UI.ModalDialog.get_childDialog(); if (dialog != null) { dialogArgs = dialog.get_args(); workflowTypeId = dialogArgs.WftId; workflowTypeColor = dialogArgs.WftColor; }
Recently when working with IE7 I found that this wouldn’t work, the value of the dialogArgs variable (above) was undefined.
Since in my code the parameter data is an object literal I’m guessing that IE7’s lack of native JSON support may be something to do with this, since it works just fine with IE8 and IE9.
One workaround is to use query string parameters appended to the dialog url, and from the dialog code to retrieve them using GetUrlKeyValue(), this is fine for simple data, but for objects it would get messy.
In this scenario another simple workaround is to retrieve the parameter data from window.frameElement;
var dialog = SP.UI.ModalDialog.get_childDialog(); if (dialog != null) { dialogArgs = dialog.get_args() || window.frameElement.dialogArgs; workflowTypeId = dialogArgs.WftId; workflowTypeColor = dialogArgs.WftColor; }
helped very much.
Thanks!