admin管理员组

文章数量:1401926

I have a popup window that closes when a Cancel button is clicked:

btnCancel.Attributes.Add("onclick", "window.close();");

but I want to use another button (Save) to insert to database, then close the window:

if( success )
{
closePopup();
}

The insert function will be in C#, not in JavaScript.

I have a popup window that closes when a Cancel button is clicked:

btnCancel.Attributes.Add("onclick", "window.close();");

but I want to use another button (Save) to insert to database, then close the window:

if( success )
{
closePopup();
}

The insert function will be in C#, not in JavaScript.

Share Improve this question edited Jan 20, 2023 at 18:01 double-beep 5,53719 gold badges40 silver badges49 bronze badges asked Mar 17, 2014 at 12:05 DevBassemDevBassem 331 gold badge2 silver badges7 bronze badges 2
  • Where is your code for opening a popup? – Murali Murugesan Commented Mar 17, 2014 at 12:17
  • open code must be in the parent page. – DevBassem Commented Mar 17, 2014 at 13:22
Add a ment  | 

2 Answers 2

Reset to default 3
ScriptManager.RegisterStartupScript(this, this.GetType(), "onclick", "window.close()", true);

window.close() will close the current window. If you want to close the opened window popup try following the below approach.

Assuming you are opening a popup with a reference like below (Parent.aspx)

var windowObjectReference;
var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";

function openRequestedPopup() {
  windowObjectReference = window.open("mypage", "Popup Page", strWindowFeatures);
}

For closing a popup (child.aspx)

 btnCancel.Attributes.Add("onclick", "parent.closePopup();");

Then (parent.aspx)

function closePopup()
{
 windowObjectReference.close();
}

Refer window.open and window.close()

本文标签: javascriptClose popup window after inserting to databaseStack Overflow