Solved

How to close a popup window in ASP.NET

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

9 Experts available now in Live!

Get 1:1 Help Now