This topic is locked

Refresh details view after popup from a custom button is closed.

7/27/2022 6:27:07 PM
ASPRunner.NET General questions
C
commodore author

I have two tables ... A and B. Table A is a Details view.

I have a custom button on table A Details view that uses Example 9 from this page https://xlinesoft.com/asprunnernet/docs/how_to_display_any_page_in_a_popup.htm.

This custom button is opening table B Add page. I placed the window.popup code in the Client After (had to use the Server section to store session variables for some of the table B add page fields) and everything works except the refresh of the table A Details view the custom button is located on is to quick. I would like to have it refresh after I close the popup.

The JavaScript Onload code is closing the popup, but since that is on the Add page of Table B, the window.parent.location.reload(); doesn't work on the Table A Details view.

if ((proxy['saved']) && window.parent && window.parent.popup) {
window.parent.location.reload(); // Replace this with the window info of Table A Details view?
window.parent.popup.close();
}

If I place pageObj.reload({}); in the Client After on the custom button, the Table A Details view refreshes. But since it's Javascript, it refreshes the data right after the popup appears and doesn't wait for it to close. I currently have a pause in there to make it refresh a little later.

Custom button - Table A Details view:

window.popup = Runner.displayPopup({
url: Runner.pages.getUrl("Comments","add"),
width: 700,
height: 700,
header: 'Add Comment'
});

// run the Server event after a 15-seconds pause:
setTimeout( function() {
pageObj.reload({});
}, 15000 );

Which leads me to the question, Can I store the window info of Table A Details view and place that in the JavaScript Onload of the Add Page of Table B in place of window.parent.location.reload(); This would hopefully allow the Table A Details view to refresh after the popup is closed.

Thanks,

Dom

Admin 7/28/2022

Hi,

it is not very clear what "window info of Table A Details view" is. Could you please elaborate?

C
commodore author 7/28/2022

https://xlinesoft.com/asprunnernet/docs/how_to_reload_a_page.htm

After some research I ran across the above page.
Using example 2 on this page I was able to store the Station Details Page Object. This is what I meant by "window info of Table A Details view".
window.StationDetailPage = pageObj;

The help then says to add the following code to any Javascript event where you want to reload the Customers table. Can be ClientAfter event of any button.

if( window.customersPage ) {
window.customersPage.reload({a:'reload'});
}

I added this code to the 'saved' window popup (see below) hoping that once the popup was saved, the table would reload but it doesn't work.

if ((proxy['saved']) && window.parent && window.parent.popup) {
if( window.StationDetailPage ) {
window.StationDetailPage.reload({a:'reload'});
}
window.parent.popup.close();
}

If I add it to the Client After of the button that calls the popup it automatically reloads when the popup is opened.

Is there any other javascript locations I can place this that will only run after the popup has been closed?

Admin 7/28/2022

Check examples 6 and 7 at https://xlinesoft.com/asprunnernet/docs/how_to_display_any_page_in_a_popup.htm
This is the closest that we have and one of those methods will help. Using Example #6, for instance, you can close the popup and then do something else.

C
commodore author 7/29/2022

Thank you, those examples did help!

I now have the page reloading after closing the popup, unfortunately a side effect is now the popup won't close by itself after saving.

I placed this code in the Client After on the button:

popup = Runner.displayPopup({
url: Runner.pages.getUrl("Comments","add"),
width: 700,
height: 500,
header: 'Add Comment',
beforeClose: function(popup) {
pageObj.reload({});
}
});

I also left the code in from example #9 (Javascript OnLoad) from that same page your noted.

if ((proxy['saved']) && window.parent && window.parent.popup) {
alert('closing');
window.popup.close();
//window.parent.popup.close();
//popup.close();
//window.win.close()
}

the alert shows after hitting save so I know it is going into the code ... but no matter what .close() I put in there, the popup remains opened.

I even tried placing this on the button thinking it would allow window.popup.close() to work.

afterCreate: function(popup) {
window.popup = popup;
},

Hopefully it's something simple, but what am I missing?