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.
ASP.NET

Avatar of undefined
Last Comment
Computer101

8/22/2022 - Mon
aki4u

try adding in AddRide.aspx, onunload(in body tag) this: window.opener.location=window.opener.location;
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.
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>")
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
aki4u

is needs to be like this:
<body onunload="window.opener.location=window.opener.location;">
Fareed Ali Khan

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);
aki4u

Solution provided!!!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
aki4u

What is wrong with the solution provided?
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
Computer101

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question