Learn more about SQL Server tools

mssqltips logo

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Scripts          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories


Redirection to another page from SP.UI.ModalDialog

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


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

Last Updated: 2011-03-02

get scripts

next tip button

About the author

Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Email me updates 

Signup for our newsletter
 I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.


Learn more about SQL Server tools