Solved

How to close a popup window in ASP.NET

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hangfire / asp.net sample 3 50
ASP.Net Session State alternatives 3 57
SQL Login 17 40
How do I prevent the pages in my site from showing up in a google search? 2 28
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now