Solved

How to close a popup window in ASP.NET

Posted on 2006-07-20
5
1,808 Views
Last Modified: 2012-06-27
Hi,

I cannot close a popup window, but I can open it. Does anybody know how to close it?


I CAN open a popup window loading Menu_Reporte.aspx inside it:
Dim popupScript As String = "<script>window.open('../Reportes/Menu_Reporte.aspx" + "',null,'menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,status=yes')</script>"
If Not Page.IsStartupScriptRegistered("OpenWindow") Then
            Page.RegisterStartupScript("OpenWindow", popupScript)
End If

I want to close the popup window with
Page.RegisterStartupScript("closescript", "<script>window.close('../Reportes/Menu_Reporte.aspx');</Script>")

But ASP.NET does not do it !
0
Comment
Question by:miyahira
5 Comments
 
LVL 24

Expert Comment

by:Justin_W
ID: 17151033
window.open() returns a "window" object. You need to call the ".close()" method on this object, meaning you need to store the object returned by window.open() in a variable, and call mywin.close() as your close script.
0
 
LVL 1

Author Comment

by:miyahira
ID: 17151102
ok, Justin W.... could you provide some code, please?
And why to open a popup window it is not needed to store any object ?

To open the popup window, just do it:

Dim popupScript As String = "<script>window.open('../Reportes/Menu_Reporte.aspx" + "',null,'menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,status=yes')</script>"
If Not Page.IsStartupScriptRegistered("OpenWindow") Then
            Page.RegisterStartupScript("OpenWindow", popupScript)
End If
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 17151782
You are opening the window on page startup and if you say....
>> Page.RegisterStartupScript("closescript", "<script>window.close('../Reportes/Menu_Reporte.aspx');</Script>")

how do you think the page would open ?
So for closing the Popup window you need some other way...may be a button on the PopUp window itself that says "self.close()"
Or a button on the Parent window which stores the window handle and closes it


0
 
LVL 5

Accepted Solution

by:
vinodhsomasekharan earned 255 total points
ID: 17151840
Hai,

 You are opening a new form "Menu_Reporte.aspx" from say webform1.aspx using registerstartup script..

  1. Are u willing to close the newly opened form   "Menu_Reporte.aspx"  from   webform1.aspx??
or
  2. Are u willing to close the newly opened form    "Menu_Reporte.aspx" from any button click in that form itself.. ??

If your option is No: 2 then you can just carry on with what justin_w said..  
Page.RegisterStartupScript("closescript", "<script>window.close();</Script>")  .. call this line in the required place in
 "Menu_Reporte.aspx"

If your option is No: 1  
then try the following in "webform1.aspx"
<SCRIPT LANGUAGE="JScript">
var objWindow;
function ButtonClick()
{
objWindow = window.open("Menu_Reporte.aspx",null,"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
}
function CloseClick()
{
  objWindow.close();
}
</SCRIPT>

<BUTTON onclick="ButtonClick()">Click Me!</BUTTON>
<BUTTON onclick="CloseClick()">Close Me!</BUTTON>

-- this works fine in client side.. if any post back occurs.. then it will be difficult..


Regards
Vinodh

0
 
LVL 1

Author Comment

by:miyahira
ID: 17154075
WONDERFULL, vinodhsomasekharan !!
It works like a charm.

I post my code, maybe somebody needs it:

In behind code of "webform1.aspx":

'MyASPButton is the button on server side that will close the Popup
'MyASPButton is on webform1.aspx
'Menu_Reporte.aspx is the aspx that is shown in popup window and I want to close

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
   Me.MyASPButton.Attributes.Add("onclick", "Close_Popup();" + Me.GetPostBackEventReference(Me.MyASPButton))
End if

In html desgin of "webform1.aspx", insert this javascript

    function Close_Popup()
    {
     objWindow = window.open("../Reportes/Menu_Reporte.aspx",null,"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
     objWindow.close();
    }
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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.…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

790 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