1

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.

double-beep
  • 5,031
  • 17
  • 33
  • 41
DevBassem
  • 13
  • 1
  • 2
  • 7

2 Answers2

3
ScriptManager.RegisterStartupScript(this, this.GetType(), "onclick", "window.close()", true);
double-beep
  • 5,031
  • 17
  • 33
  • 41
Jameem
  • 1,840
  • 3
  • 15
  • 26
  • thanks alot it works now ! your code 'ScriptManager' that works perfect with UpdatePanel. Ref. http://stackoverflow.com/a/7054225/1328869 – DevBassem Mar 18 '14 at 16:26
1

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

Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120