Redirection to another page from SP.UI.ModalDialog


By:   |   Updated: 2011-03-02   |   Comments   |   Related: > Sharepoint

Problem

Redirecting to another page from the SP.UI.ModalDialog Modal window without closing the window will not work and it always opens a new modeless window where the page will be displayed. The dialog framework supports the Source=url querystring variable like the rest of SharePoint. But this has to be part of the Dialog Options to redirect to another page. However, if you have a requirement to dynamically get the page which needs to be redirected from the dialog then this may create a problem...

Solution

The solution for the problem would be to create an intermediate html page. This would have a <frameset> html element with a single frame and set the src attribute with the page which you actually need to load inside the Modal Dialog. So now if the user clicks the link which navigates to another page, it will be opened within the same dialog window instead of a new window. Here's how it works...

Let me explain the implementation method using the example below.

Solution Implementation

Create an HTML/ASPX Page

Create an html/aspx page and place it in the _layouts folder or your respective folder. (Copy and paste the below code.)

<frameset rows="100%">
<frame src="<<replace the actual filename here>>">
</frameset>

In the above code please replace the filename with the actual page which you want the modal dialog to load.

JavaScript function to invoke the html or aspx page

<script type="text/javascript">
//Dialog opening
function OpenDialog() {
var options = SP.UI.$create_DialogOptions();
options.url = "<<replace frameset filename here>>";
options.width = 500;
options.height = 400;
options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
SP.UI.ModalDialog.showModalDialog(options);
}
var messageId;
// Dialog callback
function CloseCallback(result, target) {
if(result === SP.UI.DialogResult.OK) {
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK);
}
if(result === SP.UI.DialogResult.cancel) {
SP.UI.Notify.addNotification("Operation was cancelled...", false, "", null);
}
}
</script>

Screen shot of the sample implementation

ScreenShot

In the above shown screen shot the "View Results" link will load the poll results page within the same window.

Next Steps


Last Updated: 2011-03-02


get scripts

next tip button



About the author





Comments For This Article





download


Recommended Reading

Developer Dashboard in SharePoint 2010

Taking Control of Checked Out Documents in SharePoint

Reading SharePoint Lists with Integration Services 2017

Understanding SharePoint Exports to Excel

Recover a deleted SharePoint site or site collection with the *New* Site Recycle Bin





get free sql tips
agree to terms


Learn more about SQL Server tools