1

I have a popup window that closes when click ( Cancel ) button, code below :

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

I tried to google this issue but most solutions didn't fix it for me.

Thanks in advanced,

  • Update : insert function will be C# code, not javaScript .
DevBassem
  • 13
  • 1
  • 7

2 Answers2

2

I hope this code will solve your issue..

ScriptManager.RegisterStartupScript(this, this.GetType(), "onclick", "window.close()", true);

Please Mark as answer if it satisfies you..

Jameem
  • 1,820
  • 3
  • 14
  • 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
  • 21,923
  • 17
  • 67
  • 118