?
Solved

Close aspx page opened in a pop up window

Posted on 2011-05-11
7
Medium Priority
?
310 Views
Last Modified: 2012-05-11
I was wondering how can I close a aspx page that has been opened in a pop up window. I have an html page with a button when clicked opens the html page in a pop up window. When the submit button is clicked after processing the information I would like to close the pop up window. How can I go about doing this ?
0
Comment
Question by:pmac38CDS
7 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 35736726
Can you post the code in which you're opening the popup?
0
 
LVL 19

Expert Comment

by:Bardobrave
ID: 35736766
To close the window popup from within it's own client code use:

window.close();

To close it from parent window client code you should open the child with a reference:

childWindow = window.open(....

and after submittin use:

childWindow.close();
0
 
LVL 8

Expert Comment

by:Anurag Agarwal
ID: 35737159
pls chk the link for the answer  closing a popup form
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

Accepted Solution

by:
leakim971 earned 1500 total points
ID: 35737227
We use a counter on the main page. The popup window increment this counter at each page/popup load. If this counter if greater than 1, we assume a postback/submit was done on the popup window.

Using this script on the main page :

 	var n = 0;
	function signalPostback() {	
		alert(n++);
		if(n>1) {
			alert("second postback/refresh, we close it");
			a.close();
		}
	}

Open in new window


and this script on the popup page :

window.onload = function() {
      window.opener.signalPostback();
}

Open in new window


Test pages, the main page :
<html><head>
<script>
 	var n = 0;
	function signalPostback() {	
		alert(n++);
		if(n>1) {
			alert("second postback/refresh, we close it");
			a.close();
		}
	}
</script>
</head><body>
<input type="button" value="pop it" onclick="window.open('popup.html')" />
</body></html>

Open in new window


The popup :
<html><head></head><body onload="window.opener.signalPostback();"><form action="#">
<input type="submit" value="Postback"  />
</form></body></html>

Open in new window


If you need help to implement this with aspx don't hesitate
0
 
LVL 1

Author Comment

by:pmac38CDS
ID: 35737839
Yes I would like to implement this in the aspx.cs file. How can I go about doing this ?

Thanks,
Aditya
0
 
LVL 83

Expert Comment

by:leakim971
ID: 35738116
Check Page.ClientScript.RegisterStartupScript() on this page : http://msdn.microsoft.com/en-us/library/aa479390.aspx

On the popup page :

    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "window.opener.signalPostback();", true);
    }

Open in new window


In the header of the main page, no change :
<script language="javascript" type="text/javascript">
 	var n = 0;
	function signalPostback() {
		alert(n++);
		if(n>1) {
			alert("second postback/refresh, we close it");
			a.close();
		}
	}
</script>

Open in new window

0
 
LVL 1

Author Closing Comment

by:pmac38CDS
ID: 35871762
I had to tweak my aspx to implement the solution.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question