WebApp Parent/Child windows

T

Tomas Vera

Hello All,
I'm working on a web app that will simulate a Windows app.

One of the items that I've trouble reproducing is the parent/child
interaction that might occur between a windo and popup custom dialog
box (example: right click an item and bring up a Config/Properties
dialog of the selected item).

In a Windows app, I can add a handler in the Parent to respond to the
"OK" event in the child window so that I can update the object's
poprties and reflect any changes on the parent Window.

In the web app, I haven't been able to figure out how to hook into the
PropertyPage's "OK" event from the parent window. It seems that once I
generate a "var propPage = window.open(..)" script, that the only link
between the two windows is the "window.opener" property or the
"propPage" variable. Even then, this is a javascript relationship, not
a .NET relationship.

Currently, to simulate the parent/child interaction, I currently do
this (more or less):
1.Pop up the config page (in a small window)
2. Get the user's selections
3. Store the user's selections in the Session
4. Refresh the parent
5. Parent loads, and scans the Session for the config info
6. Parent reflects any config changes on original form.
7. Parent clears the session variable that the child set.

Is there a better way to do this?

All ideas are welcome and appreciated.

-tomas
 
J

Jerry

Hi Tomas,
There are a lot of options. It sounds like what you want to do is
POST the settings dialog and then refresh the parent. If this is the
case, then open the dialog window, keeping the window handle in a var
(like I believe you already have). Then keep polling the the dialog
window to see if it has closed... When the dialog page has closed,
then post the original window back to .Net manually. The code I've
provided below is completely self-contained on the Parent window.
There are lots of other ways to do it, hope this helps you find your
final solution.
-Jerry

// CODE for IE and Mozilla
// Variable to hold settings dialog window handle
var subWin = "";
// will hold the timeout
var tmCheck = "";
// initialize type var
var myTypeS = typeof subWin;

// function to open dialog and prep
function ChangeSettings() {
// open the new win
subWin = window.open("mypage.html","settingsDlg","toolbar=no,location=no,status=no")
;
// this is for Netscape
subWin.NSVar = 1;
//
window.onfocus = TimeRefreshThisWindow;
}

// function that sets timeout to check dialog
function TimeRefreshThisWindow() {
tmCheck = setTimeout("CheckDialog()",800);
}

// dummy function
function Nothing() {}

// function to check if dialog has closed
function CheckDialog() {
var myTypeS = typeof subWin.document;
// Has the dialog closed?
if ( ( navigator.userAgent.indexOf("IE") && myTypeS != "object" )
|| ( navigator.userAgent.indexOf("NS") && subWin.NSVar != 1 ) ) {
// bring the focus back to parent (me)
window.focus();
// refresh me (.Net must be expecting this pseudo postback,
handle it in your Page Load event or pass a control id to link it to
an event)
__doPostBack("<%=Me.ClientID%>:myControlId","") ;
// to avoid errors
window.onfocus = Nothing;
} else {
// the child still exists, make sure it has focus
subWin.focus();
}
}

// this function closes the dialog if the parent is closed
function CheckDlgOrphan() {
var myTypeS = typeof subWin.document;
if (myTypeS == "object") {
subWin.close();
}
}
// set onunload
onunload = CheckDlgOrphan;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top