Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 3rd, 2008, 12:21 PM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default 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?
Reply With Quote
  #2 (permalink)  
Old October 3rd, 2008, 02:21 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

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.
Reply With Quote
  #3 (permalink)  
Old October 3rd, 2008, 03:06 PM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

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?
Reply With Quote
  #4 (permalink)  
Old October 3rd, 2008, 03:24 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

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.
Reply With Quote
  #5 (permalink)  
Old October 4th, 2008, 02:36 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #6 (permalink)  
Old October 4th, 2008, 01:48 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

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.
Reply With Quote
  #7 (permalink)  
Old October 6th, 2008, 10:05 AM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

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!
Reply With Quote
  #8 (permalink)  
Old October 6th, 2008, 12:18 PM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

"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?
Reply With Quote
  #9 (permalink)  
Old October 6th, 2008, 12:24 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #10 (permalink)  
Old October 6th, 2008, 12:38 PM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Crystal report Freeze detail section. dpkbahuguna Beginning VB 6 0 August 23rd, 2007 05:29 AM
Change size of the Detail section of Forms/Report sinajs Access 1 February 13th, 2007 01:05 PM
Shrink Detail section on a report TimLB Access 2 January 23rd, 2007 08:45 AM
Access Report Detail lgpatterson Access 2 January 31st, 2005 08:19 PM
Formatting Report Detail Section rickf Access 3 February 3rd, 2004 07:15 PM



All times are GMT -4. The time now is 03:16 PM.


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