CommonModalDialogClose (SP.UI.DialogResult.OK, someValue) throws an error

In SharePoint 2010, I have a visual web part that uses SP.UI.ModalDialog.showModalDialog

The dialog box displays fine, but when I try to close the dialog using

SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, someValue)

I get an error

Cannot get value of property "OK": object is null or undefined

+4
source share
2 answers

A quick / hack workaround is to use 1, which means SP.UI.DialogResult.OK

Thanks, I managed to get this to work using numbers instead of SP.UI.DialogResult.OK.

For instance...

SP.UI.ModalDialog.commonModalDialogClose(0,'Canceled the dialog.'); similar to using SP.UI.DialogResult.cancel

SP.UI.ModalDialog.commonModalDialogClose(1,'Yay Success!'); similar to using SP.UI.DialogResult.OK

SP.UI.ModalDialog.commonModalDialogClose(-1,'Uh oh... Error'); similar to using SP.UI.DialogResult.invalid

+13
source

You need to include the JS file of the SharePoint SP.UI.Dialog.js file in your "dialog page".

 <SharePoint:ScriptLink Name="SP.UI.Dialog.js" runat="server" /> 

or

 <script src="/_layouts/SP.UI.Dialog.js" type="text/javascript"></script> 

A quick / hacky workaround would be to use 1 , which stands for SP.UI.DialogResult.OK .

+6
source

Source: https://habr.com/ru/post/1391534/


All Articles