Redirection to another page from SP.UI.ModalDialog

Written By: Udaya Kumar -- 3/2/2011 -- join -- contribute -- (3278) comments -- printer friendly version

Rating: Rate --

Categories: Design, SharePoint 2010, SharePoint Foundation 2010


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...


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>>">

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);

var messageId;

// Dialog callback
function CloseCallback(result, target) {
if(result === SP.UI.DialogResult.OK) {
if(result === SP.UI.DialogResult.cancel) {
SP.UI.Notify.addNotification("Operation was cancelled...", false, "", null);


Screen shot of the sample implementation


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

Next Steps

Learn more about SharePoint

Sponsor Information

Copyright (c) 2010-2017 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | contribute | feedback | about
Some names and products listed are the registered trademarks of their respective owners. |