Link to home
Create AccountLog in
Avatar of myester
myester

asked on

How to close a 2nd window and have it update the 1st window

I am developing an app in Visual Web Developer 2005 Express. I have a page I'll call the Main page. On this page I have put a webcontrols.menu control. The first menu item has its NavigateUrl field set to ~/AddRide.aspx. I click on this menu item to bring up a second window where the user can enter data to add a new record to the database with the Submit button. When the user clicks the Submit button I want AddRide.aspx to close and then the Main page to update with the new record. In VS2003 I did this with

       Response.Write("<Script> window.opener.location=window.opener.location; window.close(); </script >")

in the CodeBehind file. It doesn't work in Visual Web Developer 2005 Express. I think it's because of the way I'm opening the AddRide.aspx window. In VS 2003 I opened that window with:

       Dim strPop As String
        strPop = "<script language='javascript'>window.open('AddRide.aspx','Add_Ride','height=400, width=600, left=100, top=100');</script>"
        Page.RegisterStartupScript("Pop", strPop)

In Visual Web Developer 2005 Express I'm opening the AddRide.aspx window with the webcontrols.menu control. So my question is if I open the window with the webcontrols.menu control how can I close it and update the Main page.

Thanks for any help you can provide in my learning experience.
Avatar of aki4u
aki4u

try adding in AddRide.aspx, onunload(in body tag) this: window.opener.location=window.opener.location;
Avatar of myester

ASKER

aki4u, that doesn't work. I'm trying it like this in the AddRide.aspx page:

<body onunload this: window.opener.location=window.opener.location; >

What I want to happen is when I click on the Submit button on AddRide.aspx I want AddRide.aspx to close and the Main page to update.
Avatar of myester

ASKER

I found the answer right here in Experts-Exchange. This seems to work fine in the code behind file:

Response.Write("<script language=""JavaScript"">window.opener.location.reload();</script>")
Response.Write("<script language=""JavaScript"">window.setTimeout('window.close()',10);</script>")
is needs to be like this:
<body onunload="window.opener.location=window.opener.location;">
on submit button click write this code

string closeScript = "window.close();var xWin=window.dialogArguments; xWin.location.replace(xWin.location);";
if (!this.Page.ClientScript.IsClientScriptBlockRegistered("CloseScript"))
      this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CloseScript", closeScript, true);
Solution provided!!!
What is wrong with the solution provided?
Avatar of Bob Learned
Actually it is a PAQ refund because the Asker posted the solution and it is not related to the suggestions before it.

EE Cleanup Volunteer
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account