I have a layouts page which creates a new site. I use SP.UI.ModalDialog to show the site. I've created the following js function I use to pop it up:
function PagePopupAndRedir(fileUrl, fileTitle, fileWidth, fileHeight) {
var options = SP.UI.$create_DialogOptions();
options.url = fileUrl;
options.title = fileTitle;
options.allowMaximize = false;
options.showClose = true;
options.width = fileWidth;
options.height = fileHeight;
options.dialogReturnValueCallback = modalDialogClosed;
SP.UI.ModalDialog.showModalDialog(options);
}
the modalDialog method isn't very relevant here, but it starts like this:
function modalDialogClosed(dialogResult, returnValue) {
if (dialogResult == '1') {
window.location.href = returnValue;
}
}
In my layouts page, the last thing I do is:
var response = "<script type='text/javascript'>SP.UI.ModalDialog.commonModalDialogClose(1, 'myUrl')</script>";
Page.Response.Clear();
Page.Response.Write(response);
Page.Response.End();
I can see that the js method is called, but the problem is that the returnValue is never set, it's always undefined. However, returnValue is set in the js-method, but it's not passed based on what I pass, it's passed "directly" from the dialog. I.E. if dialog is correctly closed, it's '1', if it's aborted the value is '0'.
How do I pass parameteres from my server side code to the js-code?
Update: I have observed the funny feature: It SOMETIMES work! About 1 in a few, the parameter is actually passed through to the js-method. Nothing is changed in neither js or cs-code! WTF?