p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   Refresh report when detail changes (http://p2p.wrox.com/showthread.php?t=70863)

Ron Howerton October 3rd, 2008 12:21 PM

Refresh report when detail changes
 
This seems like an obvious issue for anybody writing a data entry program for the web, but I have been unable to find an answer:

The Browser displays a detail report. The user clicks a link on the report to edit the selected record in ANOTHER browser window. When they save the change, the second browser window is closed. They return to the report in the first browser window, which now shows outdated information. As our users cannot apparently be relied upon to refresh the report manually, I would like to refresh it automatically. Adding a meta tag to reload at timed intervals would force a refresh when one may not be necessary.

Ideally, I would like the submission of the changes to refresh the report, but that seems unlikely when these are a separate windows. In the Windows world I could do this behind the OnActivate event, but like so many useful features, that event does not seem to exist for browser based apps. And Onfocus is not available at the form level which rules out an automatic refresh when the user simply returns focus to the Report window.

Is this possible, and if so, how?

Old Pedant October 3rd, 2008 02:21 PM

Assuming that both the main window and the popup are hitting the same domain, it's trivial.

In the popup, you must have some code that closes it, yes?
    window.close( );
or maybe
    self.close( );
???

Okay, so JUST BEFORE that line, simply do
    window.opener.location.reload();

That is, as the "opener" of the popup window to force a refresth ("reload" method call).

This is not an official standard, but it works in all common browsers.

Note that if the popup is in a different domain, then you can't do this. Then you'd have to rely on a test in the main window. It's a tad more complex. Let me know if you need it.

Ron Howerton October 3rd, 2008 03:06 PM

I think there is a misunderstanding of the scope:

The EDIT window is not a pop up, at least as I understand pop ups, anyway. It is being opened by an <a> tag, not script that links the two pages together via a handle (such as might be expected when opening a pop up calendar from JS to select and fill in a date on an edit page, for example). I also am not sure what you mean by "hitting different domains". The edit page is generated by .NET code that resides in the same virtual folder and server as the report code. Finally, there is no "close" logic. The user may close the EDIT window using the X in the upper right hand corner of the browser, click a close button, or use Task Manager, for that matter.

So, I am not sure how this example would help. If this code is meant to reside in the close logic of the EDIT page, it would appear to me to refresh the EDIT page, not the REPORT page. What am I missing?

Old Pedant October 3rd, 2008 03:24 PM

Whether the popup is generated by a <FORM> submit or by something like
    <a target="_blank" href="edit.aspx?...">...</a>
is immaterial.

*IF* this is truly a separate window that pops up (that is, if you can drag it around on the screen separately from the main window), then it *WAS* opened by the main window. In which case
     window.opener
does indeed refer to the main window.

Yes, of course they are in the same domain if they are all part of the same ASP.NET project. Different domains would be "www.yoursite.com" versus "www.someOtherSite.com".

I gave you the JavaScript/HTML answer. How you incorporate it into ASP.NET pages is up to you. Since I don't know how/what is closing the popup, I can't guess more than this.

****************

*IF* you mean that ASP.NET is generating just a <DIV> that pops *ON* to the main page (that is, it's really part of the same window, it just has a z-index that puts it in front of the other content), then the answer will be a bit different. And, likely, you could do it all in ASP.NET server-side coding.

I've done ASP.NET, but not much and mostly back in version 1, so if this turns out to be really an ASP.NET question, I'm likely the wrong person.

Imar October 4th, 2008 02:36 AM

If you are using .NET code, what about a Timer control in an update panel that posts back to the server to see if there's new data and then do a full post back when there is?

That way, most of your page stays the same while you ping back to the server. Only when there's new data, the page is completely refreshed.

You could also do this with an iframe that periodically checks the server.

HtH,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

Old Pedant October 4th, 2008 01:48 PM

I guess that works, but seems overly complicated.

The javascript
    window.opener.location.reload();
is so clean and neat that I can't see why you would work harder.

And if this is *NOT* generating a popup (but is just using a popon), then the ASP.NET logic for forcing the reload should be easy.

My cross-domain solution is similar to the timer answer, but in that case I don't assume that the main window has access to any of the data entered in the popup window. So I use a JS setTimeout that simply goes and looks every second or so to see if the popup window sitll exists. If not, then it forces the reload. Actually, pretty trivial JS code.

Ron Howerton October 6th, 2008 10:05 AM

Unfortunately, Checking for an update takes as long as refreshing the report, so there's little point in going that direction (although I can see where this would help in other circumstances). I was not aware that IE kept track of which windows were opened by which other browser windows except when using script to open them with a handle for reference. I'll attempt the window.opener suggestion assuming I can figure out where to implement it.

Thanks!

Ron Howerton October 6th, 2008 12:18 PM

"window.opener.location.reload();" displays this prompt for the Report page when it runs:

This page cannot be refreshed without resending the information.

I get the same dialog when I try this:

window.opener.history.go(0);

Now, I'm smart enough to know that I just need to click retry to resubmit the report, but I'm afraid I cannot say the same for our end-users (who obviously cannot even click the refresh button on their own). Half of them will click cancel just to prove they're idiots. ;)

I've also tried resetting "opener.href", but that threw an error because the Report code behind could no longer find the report selection page form fields using Request.Form.

And this:

window.opener.history.go(-1);

Returns the user to the report selection page, and all of their input is cleared.

None of these is the ideal solution. Isn't there some way to prevent that unnecessary "resend" dialog box from appearing?

Imar October 6th, 2008 12:24 PM

I am not sure, but I don't think you can do it. Typically, users are told to click Cancel to stop them from executing the request again, possible executing a credit card payment or some other expensive action twice.
Quote:

quote:Checking for an update takes as long as refreshing the report
Not if you keep track of changes in the code that updates the data. That is, don't execute the underlying queries again, but simply check a field (like a session variable) that indicates you need to refresh the data, and clear the field (or set it to false) if you've refreshed it.

Hope this helps,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

Ron Howerton October 6th, 2008 12:38 PM

Imar,

I'm beginning to think you are right - once again there is no solution to what should be a very simple issue (TYVM MS!)

Tracking changes on the edit form only appears to work if the current user is the ONLY user editing data in the Report. Unfortuantely, this Report needs to be refreshed even if the current user has not changed anything on the record they are viewing in the editor.

Guess I'll try the timed refresh next, as that appears to be the only viable solution at this point. Thanks!


All times are GMT -4. The time now is 08:56 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.