As we all know that sharepoint 2010 is opening a lot of forms in its newly featured model dialog.
Few of this pages are list forms like NewForm.aspx, EditForm.aspx, DispForm.aspx, pages while creating new object like list,site…etc.
While customize your sharepoint site, if by any chance you required any of your page to show in model dialog then below is the code for the same.
function OpenDialog(strPageURL,strDialogTitle) {
//Creating New Object for SharePointDialog
var newDialogOptions = SP.UI.$create_DialogOptions();
//set URL for Dialog to open
newDialogOptions.url = strPageURL;
//you can set your custom size by setting height and width
autoSize: true,
//set title to show on head of dialog
newDialogOptions.title = strDialogTitle;
// This line required only if you want to call a function when we close dialog -- here we refresh the page
newDialogOptions.dialogReturnValueCallback = Function.createDelegate(null,CallbackFunc);
//open the dialog
SP.UI.ModalDialog.showModalDialog(newDialogOptions);
return false;
}
function CallbackFunc(result, target) {
//Refresh the current page
location.reload(true);
//some suggest to use below line but sometime this was not working
//so we are working on that
//SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
}
The good thing for us is you can open any page with this dialog.
That page might have you custom webpart as well or anything will work.
Even JavaScript, query string, postback etc… available on that page because that page work similar as normal page it will also remove limitation of traditional model dialog.
If we want to refresh parent page after closing popup then also we can do that (as shown in code)
One more thing if you want to open another model dialog from already open model dialog then also this one is working
Thanks Antonio Lanaro for his wonderful post on this one.
Enjoy the popup.
2 comments:
hello
i have the same requierement.
but this did not work for me in IE v8 and it work fine with FireFox and chrome.
any suggestion ?
thank you a lot.
Ben,
this javascript is default and sharepoint also internally use this.
so this should work, we checked and its working perfectly fine in IE.
just put alert after each line and check where exactly its breaking.
Post a Comment