Close aspx page opened in a pop up window

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 ?
LVL 1
pmac38CDSAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
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
 
Luis PérezSoftware Architect in .NetCommented:
Can you post the code in which you're opening the popup?
0
 
BardobraveCommented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Anurag AgarwalCommented:
pls chk the link for the answer  closing a popup form
0
 
pmac38CDSAuthor Commented:
Yes I would like to implement this in the aspx.cs file. How can I go about doing this ?

Thanks,
Aditya
0
 
leakim971PluritechnicianCommented:
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
 
pmac38CDSAuthor Commented:
I had to tweak my aspx to implement the solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.