Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a generic page below as a tester for refreshing the page from the closing of the Modal dialog window:

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"     Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Main.aspx.cs" Inherits="Test_ApplicationPageRefresh.Layouts.Test_ApplicationPageRefresh.Main" DynamicMasterPageFile="~masterurl/default.master" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<script language="javascript" type="text/javascript" >



 function openCommentsDialog() {



     var options = {
         url: "/_layouts/PopOut.aspx",
         title: 'Pop Out',
         allowMaximize: false,
         showClose: true,
         width: 800,
         height: 330,
         dialogReturnValueCallback: Function.createDelegate(null, function (result, returnValue) {

             SP.UI.ModalDialog.RefreshPage(result);
             RefreshPage();
         }
     )
     };
     SP.UI.ModalDialog.showModalDialog(options);




 }





 function ReloadPage() {
  window.location.reload();
 }





</script> 

</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">





Main Page

<input id="Button1" type="button" value="Press Me" onclick="openCommentsDialog();"/>
<asp:Label
ID="lblRefresh" runat="server" Text="Before"></asp:Label>
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Application Page
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
My Application Page
</asp:Content>

The delegate function never fires however and the page is never refreshed. I am wondering why the page never refreshes?

share|improve this question
    
Having the same issue with GridView not refreshing after a RefreshPage. Looks like as you can't use server side code on Custom List Form (I'm on Sharepoint Online as well) it's not rebinding. Datasources are getting picked up, just not bound to asp:gridview. Only solution I can use is location.reload(true) or as shown above. However, problem with setting scroll position still eludes me. Anyone out there solved this issue. thanks. john. –  user13785 Dec 24 '12 at 16:28
add comment

1 Answer

Try

var options = {
     url: "/_layouts/PopOut.aspx",
     title: 'Pop Out',
     allowMaximize: false,
     showClose: true,
     width: 800,
     height: 330,
     dialogReturnValueCallback: function (result, returnValue) {
           window.location.href = window.location.href;
     }     
 };

Notice that this will ALWAYS reload your parent windows regardless it was closed using a button or a close/cancel button. If you need to check how it was closed, use the SP.UI.DialogResult Enumeration. More here http://msdn.microsoft.com/en-us/library/ff409060.aspx

share|improve this answer
    
Others mentioned: SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK); –  user8746 Sep 17 '12 at 21:43
    
What is the difference between SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK); and Page.Response.Redirect.HttpContext.Current.Request.Url.ToString(), true); and window.location.href= window.location.href? I ask because I have a gridview on my production page and a button with a click event with Page.Response.Redirect actually refreshes the grid on the page will window.location.href nor SP.RefreshPages does not. –  user8746 Sep 17 '12 at 21:46
    
Page.Response.Redirect is a server function. SP.UI.... are client side functions. window.location.href = window.location.href is reloading your browser like you're entering the current url for the first time (without loading again cached resources and all that stuff). The SP.UI.ModalDialog.RefreshPage(enumvalue) only refreshes the page if the value is the 'OK' enum value. (just tested it on firefox) –  Jaime Sep 17 '12 at 21:58
    
The problem is I am creating the gridview dynamically inside a webpart. The window.location.href does nothing because of this. When I incorporate the SP.UI.ModalDialog.Refresh, the page refreshes but not the grid. Any help would be much appreciated. I can send you some code if necessary –  user8746 Sep 17 '12 at 22:12
    
can you provide some code? –  Jaime Sep 17 '12 at 22:21
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.