kevin
kevin

Reputation: 14065

How to refresh a parent page after closing sharepoint dialog?

How to refresh a parent page after closing sharepoint dialog? Here is my coding to open a pop-up.

<input type="button" value="Add" class="button submit" style="width: 80px" onclick="javascript:OpenAttachmentUpload()" />

<script type="text/javascript">

    //User Defined Function to Open Dialog Framework
    function OpenAttachmentUpload() {

        var strPageURL = '<%= ResolveClientUrl("~/Dialogs/AttachUpload.aspx") %>';
        //OpenFixCustomDialog(strPageURL, "Attachment");
        OpenCustomDialog(strPageURL, 350, 200, "Attachment");
        return false;
    }
</script>

here is the script.

function OpenCustomDialog(dialogUrl, dialogWidth, dialogHeight, dialogTitle, dialogAllowMaximize, dialogShowClose) {

    var options = {
        url: dialogUrl,
        allowMaximize: dialogAllowMaximize,
        showClose: dialogShowClose,
        width: dialogWidth,
        height: dialogHeight,
        title: dialogTitle,
        dialogReturnValueCallback: Function.createDelegate(null, CloseCallback3)
    };
    SP.UI.ModalDialog.showModalDialog(options);
}

After opening it, when I close the pop-up (~/Dialogs/AttachUpload.aspx) , I wanna refresh the parent page. How can I do it? I google and see SP.UI.ModalDialog.RefreshPage but still can't find an answer for me. Thanks.

P.s I don't know much about SharePoint.

Upvotes: 16

Views: 47300

Answers (5)

Atul
Atul

Reputation: 39

Try java-script code as below in Closecall back.

window.location = window.location;

Upvotes: 1

Indy411
Indy411

Reputation: 3766

If you only want to refresh the page if changes were made you can use the following call back instead.

var options = 
{
    url: dialogUrl,
    allowMaximize: dialogAllowMaximize,
    showClose: dialogShowClose,
    width: dialogWidth,
    height: dialogHeight,
    title: dialogTitle,
    dialogReturnValueCallback: function(dialogResult) 
    {
        if (dialogResult != SP.UI.DialogResult.cancel)
        {
            SP.UI.ModalDialog.RefreshPage(dialogResult)
        }
    }
}

Saves you from refreshing the page if the user hit cancel.

Upvotes: 1

Amay Kulkarni
Amay Kulkarni

Reputation: 838

Try to use this code on click of a button:

<script type="text/javascript">
    function RefreshParent() 
    {
        SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Ok, null);
    }
</script>

Upvotes: 1

Baris
Baris

Reputation: 261

You can also use the build-in function "RefreshOnDialogClose"

 SP.UI.ModalDialog.showModalDialog({
    url: dialogUrl,         
    allowMaximize: dialogAllowMaximize,         
    showClose: dialogShowClose,         
    width: dialogWidth,         
    height: dialogHeight,         
    title: dialogTitle,         
    dialogReturnValueCallback: RefreshOnDialogClose  
}); 

Upvotes: 26

Stefan
Stefan

Reputation: 14880

You're almost there.

In the option dialogReturnValueCallback you can define a function that will be executed after the dialog was closed. By now you create a delegate pointing to CloseCallback3 but this is not defined in your code.

If you call SP.UI.ModalDialog.RefreshPage in this callback method the page gets refreshed after the dialog was closed with OK.

 var options = 
 {
        url: dialogUrl,
        allowMaximize: dialogAllowMaximize,
        showClose: dialogShowClose,
        width: dialogWidth,
        height: dialogHeight,
        title: dialogTitle,
        dialogReturnValueCallback: function(dialogResult) 
        { 
          SP.UI.ModalDialog.RefreshPage(dialogResult) 
        }
 }

Btw: You use javascript: in the onclick of the button. This is not necessary. this is only required in the href of an a tag

Upvotes: 26

Related Questions