最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Close popup window after inserting to database - Stack Overflow

programmeradmin7浏览0评论

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()

发布评论

评论列表(0)

  1. 暂无评论