Solved

How to close a popup window in ASP.NET

Posted on 2006-07-20
5
1,809 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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