Solved

How to close a popup window in ASP.NET

Posted on 2006-07-20
5
1,810 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

688 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